Creating an Application Development Framework Using Enterprise Templates - Part 1, Page 5
Encryption and decryption of configuration settings
As the name suggests, the Visual C# class library project named Encryption provides the functionality to encrypt and decrypt configuration settings. For example, we might want to encrypt the value while storing the connection string within the configuration file and then decrypt that information at runtime to connect to the appropriate backend database. For performing encryption and encryption, we use the Triple Data Encryption Standard algorithm that is implemented by the System.Security.Cryptography.TripleDES class.
All the encryption related classes are implemented in the class library project Encryption. There are four classes in this project named Encryptor, Decryptor, EncryptTransformer, and DecryptTransformer that provide this functionality. Again the code for this reusable component can be downloaded along with the support material for this article.
Utilities Class Library
- Sending mails using SMTP service — This is accomplished using the classes contained in the System.Web.Mail namespace.
- Raising SoapExceptions — Exposes helper methods that allow us to raise SoapExceptions in a standardized and consistent manner.
- Performing XML transformations by applying XSL stylesheets — This is implemented using the classes contained in System.Xml and System.Xml.Xsl namespaces.
Default Configuration Settings for the ASP.NET Web UI and Web Service Applications
Since we are creating this base template for creating web-based E-commerce applications, we can pre-define some of the common parameters used by our web application. For example, since we want our web application to be scalable, we can enforce the use of SQL Server based session state management capabilities by pre-populating the sessionState element in the web.config file with appropriate values.
Let us start by creating a new ASP.NET web application named WebUI, selecting Visual C# as the language of choice. The following list identifies the configuration parameters that we want to pre-populate when our template is used to create an E-commerce application.
- Session state management — For storing session state, we will use the SQL Server based session state management capabilities provided by ASP.NET. To accomplish this, we will need to add the following settings.
<sessionState mode="SQLServer" sqlConnectionString="data source=testsource;uid=uid;password=password" cookieless="false" timeout="20" />
- Exception management application block related settings — The exception management block supplied by Microsoft makes it possible to manage exception-logging capabilities by having entries in the web.config file. In our application, since we always want to log exceptions in a separate event log (named AppEventLog), we will add the following settings.
<exceptionManagement mode="on"> <publisher assembly="Microsoft.ApplicationBlocks.ExceptionManagement" type="Microsoft.ApplicationBlocks.ExceptionManagement.DefaultPublisher" logname="AppEventLog" applicationname="Custom Distributed App Template" /></exceptionManagement>
- Custom configuration section handling related sections — Each custom configuration section is represented by a section named appConfigSection.
<configuration> <configSections><section name="appConfigSection" type="Distr.AppFramework.ConfigurationHandler.ApplConfigSectionHandler,ConfigurationHandler"></section> </configSections> ... <appConfigSection> <appSection name="exampleSection" encrypted="false"><appSetting key="key1" value="value1"></appSetting> </appSection> </appConfigSection></configuration>
- Common page to redirect to, when an exception occurs in our application — This is set to ErrorPage.aspx
<customErrors defaultRedirect="Common/ErrorPage.aspx" mode="RemoteOnly" />
- Authentication model for the web application — We will set the authentication model to forms based authentication by using the following setting.
<authentication mode="Forms"> <forms name="DistributedAppAuth" loginUrl="Login.aspx" path="/"></forms></authentication>
As you can see from the above setting, we are also pre-defining the login page as Login.aspx.
For the ASP.NET web service application, since we dont our web service to be accessible over HTTP Get and HTTP Post (except for testing purposes), we will add the following entries directly under system.web element.
<webServices> <protocols> <remove name="HttpPost" /> <remove name="HttpGet" /> </protocols></webServices>
So far, we have seen the different building blocks that will provide the core foundation for building the enterprise template. In the Part-2 of this article, we will see customize the enterprise template and add these building blocks as part of the template.
Download Source Code: ETemplates.zip - 95 kb
About the Author
Thiru has six years of experience in architecting, designing, developing and implementing applications using Object Oriented Application development methodologies. He also possesses a thorough understanding of software life cycle (design, development and testing).
He is an expert with ASP.NET, .NET Framework, Visual C#.NET, Visual Basic.NET, ADO.NET, XML Web Services and .NET Remoting and holds MCAD for .NET, MCSD and MCP certifications.
Thiru has authored numerous books and articles. He can be reached at email@example.com.
# # #
Page 5 of 5