Configuration in ASP.NET

When you install a new application, you may be required to configure it. For example,you may need to provide information about the amount of memory to be used by the application. In addition, you may need to specify application-specific information, such as the path for the data source. A configuration system provides all this information for an application, which may be used at the time of or after the deployment of the application.

A Web application should provide a flexible configuration system that allows configuration settings to be easily applied to the application. It should also facilitate easy customization of configuration settings after the deployment of the application so that changes in the configuration settings can be applied to the application without having to recompile the entire code. In addition, the configuration system should provide a rich set of configuration settings to enable different types of Web clients to work with the applications.

The configuration system provided in ASP.NET meets all of these requirements. It provides a flexible configuration system, as well as a rich set of initial configuration settings. A thorough understanding of the configuration system helps you to easily specify the settings for the target computer. You can also easily change the settings after the application is deployed.

In ASP.NET, the configuration file Web.config stores the information about browser capabilities, compilation, custom error messages, security, and globalization. The Web.config file stores the configuration information in an XML format; therefore, it can be easily read and modified by developers by using any standard text editor. Developers can also use scripting languages such as Perl and VBScript to navigate, interpret, and modify the configuration settings specified in the file.


ASP.NET provides a default configuration file for the entire Web server. This file provides the default settings for an ASP.NET application. This file, called Machine.config, is located in the %windir%\Microsoft.NET\Framework\version\CONFIG folder and is available at the machine level. In addition to this machine-level file, you can create your own Web.config file that specifies the settings for a particular application.

When a user makes a request for a resource, ASP.NET determines the configuration settings for the resources by referring to the settings in the Web.config file located in the path of the resource. In the absence of this file, ASP.NET refers to the settings in the Machine.config file.

Deploying Classes and Assemblies

A Windows application is composed of different types of files, such as EXEs and DLLs. When you deploy a new application, it might result in the installation of all the files that comprise the application. However, this may cause a number of problems, especially in case of applications that use COM-based components. COM components need to be registered so that the system can locate them. This requires several Registry settings, in the absence of which the components do not work. In addition, if an application results in installing a newer version of a component, which is shared by a number of applications on a computer, the existing applications might not work as expected.

To overcome the problems of COM-based components and to simplify the process of deploying classes and components, .NET introduces the concept of assemblies. An assembly is a single logical unit of functionality. It is the fundamental unit of class deployment.

An assembly contains an assembly manifest, which contains data about the dependencies of the files that are included in the assembly, their version requirements, security information, and all other information required to resolve references to resources and classes in the assembly.

After you have created an assembly, you can easily deploy it by using Windows Installer (as an MSI file), by using Internet Explorer (as CAB files), or simply by copying the assembly to the target computer. An assembly can be deployed into the local assembly cache or the global assembly cache. The local assembly cache is specific to an application. On the other hand, when you install an assembly into a global assembly cache, it can be accessed by all applications on a computer.

Usually, assemblies are deployed into the local assembly cache of the application. This ensures that the assembly can be accessed only by the code in the application. It also facilitates side-by-side versions of an application to run simultaneously, because the classes of the assemblies are private to a particular application version instance. You can deploy an assembly into the local assembly cache by copying the assembly files in the directory, which is marked as the assembly cache location for an application.

ASP.NET applications are configured to use the bin directory specific to an application as the default local assembly cache. Therefore, you can copy the assembly files to the bin directory of the application.

You can install an assembly into the global assembly cache, using Windows Installer, when you want multiple applications to share the code in the assembly. Windows Installer 2.0 provides the reference-counting feature for assemblies that are shared by multiple applications.

How to Perform Web Testing using Visual Studio 2005

The Visual Studio 2005 Team System enables Web Testing which makes it easy for testing your website without writing any code. When we say web testing, the Visual Studio 2005 Team System Web testing does not do any user interface testing; instead the tests are done against the data that is flowing through the HTTP. This data is examined and validated with various rules in place.

Testing a web page for the validity of the JavaScript of that page is not done with Visual Studio 2005 Team System or the compatibility of the page for every browser is not tested. There is a step by step approach that can be used to test the website without writing any code. However it is also possible to test the website by writing your customized code as well. The built-in web testing support can also be extended in the Visual Studio 2005 Team System.

Activity recording is supported in Visual Studio 2005 Team System. With this feature in Visual Studio 2005 Team System you can do automated tests against a website by just browsing through the website and filling the forms if present. This automated testing feature is more useful to test a website. So for using the Web Testing feature of Visual Studio 2005 Team System you have to set up a website and a test project.

Create a personal website using the New Web Site option in the File menu. Then select the Personal Web Site Starter Kit and choose the programming language in which you want to create the website. Once the website is created, you have to create a new account so that you can test the website using that account automatically. Open up the website administration tool by clicking the Website and then the ASP.Net Configuration. Use the Security link and then the Create User link to create the user. Let the role of the user be Administrators. Then close down the website.

You should know that IIS is not used to host the website instead Visual Studio 2005 starts an ASP.Net Development Server. This server chooses a port randomly for hosting the website. If you test a website and then restart the Visual Studio 2005 then the port used changes and hence the tests recorded earlier would become invalid. It is possible to configure Visual Studio 2005 to use a particular port all the time. Press F4 and go to the Properties window. Here you can see that the ‘Use Dynamic Ports’ value is set to True. Change this to False and select a port number to use.

The next step is to create a Test project. Add a project using the ‘Add Project’ option by right clicking the Solution. After selecting the language of your choice, select the node ‘Test’. Name your test project with an extension .Test. Now we are ready to record the activity against the website that we have already with us. Now right click the project you have and click Add. Next click ‘Web Test’. After you click ‘Web Test’ a new window opens up. This new window has an explorer bar which is a Web Test Recorder.

Type the URL of the site to be tested in the address bar. Don't forget to enter the port number of the URL. Now use the user name and password that you have created earlier to enter the site. You activities like browsing to the website URL and submitting the form information will be recorded by the Web Test Recorder. This recorded information is used automatically when you run the Web test against this website. The coordinates at which you clicked the login button is also recorded.

You can also add other steps that can be used for testing, like logging out of the site, entering the site with incorrect login information etc. once you have recorded your activity you can close the window and then save the test. Now if you look at your project, it will have a Web test case file in it which has the information that was recorded while you used that website earlier.

If you want to modify the data that was recorded while you browsed your website, you have to use the Web Test tree and selecting the appropriate node and then use the Properties window. It is also possible to group a set of requests to make them as a single unit of transaction. For your reference you can add comments to each of the request made. Just right click the request and use ‘Insert Comment’. The comments that you enter are used to document the data that is submitted.

After a test is recorded you are ready to run execute a test against a website. To do this, just run the project and this will open up a Test window that will display the test that are being run and the ones that are pending. Remarks such as Passed / Failed are also displayed depending on the condition. You can also use the Test Manager and Test View window to select a Test and execute it individually.

You can also run the individual web test files. For this, all you have to do is to open that web test file and click the ‘Run’ button. This will run the web test case. The result of each request in a test is recorded. You can view the details of the results by selecting the request. With this you can also view the html of the resulting page. While a test is executed all hyperlinks in a page are tested for their validity. These hyperlinks appear as child nodes of the request. The child nodes have the status of the request made to that URL.

For proper testing just checking the hyperlinks is not sufficient. Extraction Rules and Validation Rules are also use to check the website URLs. There is a need to check whether the user has entered the correct login information. If there is any mistake in that then the request should return an Error page. If the login is successful then the user should be directed to their account page. For this kind of testing you need the extraction rules and the validation rules.

The extraction rules are used to capture the response value. They focus on a particular value in the response got. This information might be used in the other post backs made. Option like ExtractHiddenFields, ExtractAttributeValue, ExtractRegularExpression, ExtractText and ExtractHttpHeader are available for this purpose. The validation rules are used to examine the response and see whether that response is correct for the information posted. For any failed request you can check the details using the Details tab. Some of the validation rules that are used include ValidationRuleRequiredAttibuteValue, ValidationRuleFindText, ValidationRuleRequiredTag, and ValidationRuleRequestTime.

The property window of the request rules have the feature to modify the value that is used for testing the website. One of the powerful features of Visual Studio 2005 Team System is the ability to use data that is available from a database to be used for the web test requests made. The toolbar on the Web test has feature called Add Data Source which can be used to add a data source that can be used to pull in data for testing a website. It is also possible to extend the Visual Studio 2005 Team System to write custom code for Web test and to extend its functionality. For more details on these features you can always check the MSDN documentation available in the Microsoft website.