ThreadAbortException

February 2006 Entries

ASP.NET 2.0 - Website Configuration Management from IIS

Many of us are aware that ASP.NET 2.0 provides a Website Administration Tool from where we can manage the settings for the web application.

However, we can also manage the website settings from the IIS - Virtual directory settings.

Steps

1. Click "Start" and select "Run"

2. Type "inetmgr" and press "Ok" or Hit "Enter"

3. IIS Control Panel Opens.

4. Expand the appropriate nodes to navigate to the Virtual directory of your application.

5. Select the Virtual Directory and Right Click and select "Properties".

6. You will notice that there is a New "ASP.NET" Tab. This Tab features once you install the .NET Framework 2.0.

7. Switch to the "ASP.NET" Tab.

8. There is a Version selector from which you can select the version you would like to use for your application. However, since we are dealing with ASP.NET 2.0, we will leave it to the default one that would be selected i.e. 2.0.50727. We can change it if its showing a older version.

9. Also, there is an "Edit Configuration" button in the bottom in the same Tab.

10. Clicking on it will open up the ASP.NET Configuration Settings for that application.

We can "Add", "Edit", "Remove" and "Reset" the setttings. We can manage as many settings as Authentication, Authorization, Session State, Custom Errors etc., from this Utility.

This would be very useful when we deploy our applications and would like to change the settings over the deployment environment.

Cheers and Happy Programming !!!

Getting the IE Webcontrols work in ASP.NET 2.0 while using Visual Studio 2005

Visual Studio 2005 introduced a new model for developing ASP.NET Applications without requiring an IIS on the development machine. (In fact it has been for some time with WebMatrix, Cassini Webserver etc., but this is the full fledged Visual Studio Product that has come out with this feature).

When we create an ASP.NET application using Visual Studio 2005 and try to run the application, we can momentarily notice the small Icon that comes in the Right bottom corner of the system. It is actually the built-in webserver used for running ASP.NET Applications locally.

Though the usage of this is limited to local system, it can be very useful for development scenarios where you dont need to have IIS installed for developing web applications.

Having said that, the link between IIS Virtual directory and your web application is cut off and you can create the application even in your file system folder (not the conventional c:\inetpub\wwwroot) and get ASP.NET Web applications Run / Debugged in your machine.

If we would like to use the IE Webcontrols which we have been quite familiar with, working in the ASP.NET 1.x versions, we need to customize a little bit to get them working. The webctrl_client folder which contains the scripts and images for the IE Webcontrols to render had to be present in the c:\inetpub\wwwroot folder in traditional ASP.NET 1.x applications.

Here, the folder needs to be part of the root directory of your application. Say, we have an application in c:\MyWebsites\MyTestApplication. Then the webctrl_client folders needs to be inside the MyTestApplication folder.

Secondly, we need to specify this setting in the web.config, as follows:-

<configSections>
<section name="MicrosoftWebControls" type="System.Configuration.NameValueSectionHandler,System,Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</configSections>

<MicrosoftWebControls>
<add key="CommonFiles" value="/MyTestApplication/webctrl_client/1_0/"/>
</MicrosoftWebControls>

The above settings go within the <configuration> </configuration> section of the web.config.

Please note that this setting is not required, if we create a virtual directory in the IIS for our application and the webctrl_client folder is already a part of c:\inetpub\wwwroot folder.

This is required only if we use the Visual Studio's built-in web server which uses localhost:PortNumber for running locally and debugging.

Also, its worth to note that there are better equivalent controls in ASP.NET 2.0 for the IE Webcontrols such as the ASP.NET 2.0 TreeView, MultiView controls which have better performance than the IE Webcontrols.

In fact, for TreeView, its better to use the ASP.NET 2.0 TreeView control rather than the IE Webcontrols TreeView.

The Tabstrip is the only thing for which you may want to continue with the IE Webcontrols where you can specify AutoPostBack="false" and thereby, avoid postback when hopping between the Tabs.

Cheers and Happy Programming !!!

ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

You may receive the error "The request failed with HTTP status 401: Access Denied." when trying to access a Webservice from your ASP.NET Application.

This normally indicates that Anonymous access has been disabled for the Webservice.

Also, when you try to step into the webservice using the Visual Studio debugger, "Unable to automatically step into the server. The remote procedure could not be debugged. This usually indicates that debugging has not been enabled on the server. See help for more information"
in this scenario.

We can resolve this issue by either of the following ways:

1. Enabling Anonymous Access in the IIS Directory Security

To do this, the following steps will help you.

1. Click "Start" - "Run" - Type "inetmgr" and press "Ok" or "Enter" Key

2. IIS Control panel opens.

3. Expand the appropriate nodes and navigate to the virtual directory of your Web Service Application.

4. Select the Virtual directory, Right Click and select "Properties"

5. Switch to the "Directory Security" Tab and then Click "Edit".

6. Check the "Anonymous Access" CheckBox.

7. Click "Ok" twice to exit.

This should solve the issue.

2. Programattically assigning the Credential Cache

In case you dont have access to change the IIS Settings or you just dont want to allow anonymous because other applications are using it, then you can programatically provide the permissions by specifying the credential cache.

Let us assume we have a Webservice, Service which has the default Web Method HelloWorld. Let us see the steps involved in accessing the service.

Service Service1 = new Service();
Service1.PreAuthenticate = true;
Service1.Credentials = System.Net.CredentialCache.DefaultCredentials;
Response.Write(Service1.HelloWorld());


As you can see, we are passing the CredentialCache object for the Service1.

This would ensure that we preauthenticate the access to the Service. This would be applicable in the case of Integrated Windows Authentication scenarios.

Cheers and Happy Programming !!!

Visual Studio 2005 Web Application Projects and Web Deployment Projects

Ever wondered where the "File - New - Project - ASP.NET Web Application" Icon went off in Visual Studio 2005, while it was there in Visual Studio.NET 2003 and earlier versions?

Visual Studio 2005 Development Team just thought that they could provide a newer option for creating web sites. So, it is actually moved to "File - New Website - ASP.NET Website" and the same holds good for ASP.NET Webservice". The other reason behind this might just be the compilation model for ASP.NET Applications which has been totally shifted to ASP.NET rather than Visual Studio. Now, both the ASPX Pages and the Code Files are compiled dynamically.

For more quick facts about Visual Studio 2005, check my earlier article
Quick Facts about Visual Studio 2005 - Did you know?

However, if you are still in love with the older way and want to create Web Applications by chosing "File -New - Project" option, there has been a VS 2005 Web Application Project utility released by Microsoft. Scott Gu has a detailed coverage and download link for the same, in this recent Post. You can read the article and also download the project from here.

This option is just an add-in to Visual Studio 2005 and doesnt replace the "File - New - Website" Model. In fact, both the models are going to be included and supported in the future releases of Visual Studio.

Similarly, if you are fond of the older way of deploying files (Single BIN Folder with assemblies and ASPX Pages), there is a
VS 2005 Web Deployment Project Utility which would help you in making your deployment in a traditional way that you have been doing with earleir Visual Studio .NET versions.

For a detailed article on Visual Studio 2005 Web Deployment Project Enhancements, check
Wayne Brantley's article

Cheers and Happy Programming !!!