Archive for July, 2008

ASP.NET AJAX & XHTML Conformance

Posted: July 25, 2008 in AJAX, ASP.NET
Tags: ,

For the past few days I faced strange problems while implementing ASP.NET AJAX UpdatePanel in an application running on framework 3.5.The same page was using ASP.NET AjAX ScriptService perfectly fine.On examining the HTML source of the page I found that the markup and <script> tags required for proper functioning of ASP.NET Ajax was not emitted at all.This application was actually migrated from 1.1 to 3.5 using the application migration wizard.While migrating the application the wizard adds the following lines of code web.config

<system.web>
        
<xhtmlConformance mode=”Legacy” />
</
system.web>
This was the main culprit.The markup emitted by framework 1.1 is not XHTML compliant.So to maintain compatibility the xhtnmlConformance mode is set to Legacy.The other two values are “Strict” and “Transitional”.ASP.NET AJAX UpdatePanel does not work properly with XHTML Conformance mode legacy.Changing the mode to Strict or Transitional was causing distortion and javascript related issues.In legacy mode the id of the server controls is rendered as UserControlID:ControlID whereas in mode Strict or Transitional it is rendered as UserControlID$ControlID.

So we evaluated the option of setting XHTML conformance mode to Legacy for the existing folders and Transitional or Strict for the folder containing new web pages using the <location> tag in Web.config.This also did not workout as the application uses FrontController pattern for page to page and menu navigation.So all the requests are first send to the frontconroller and then to individual pages using Server.Transfer.As the requests are not directly routed to pages in the new folder XHTML conformance mode was not changed.

So we added another aspx pointing to the same httpHandler and manipulated the location tag as follows:

<configuration>
   <system.web>
      <httpHandlers>
         <add verb="*"
              path="OldFrontController.aspx"
              type="MyHandler.New,MyHandler"/>
         <add verb="*"
              path="NewFrontController.aspx"
              type="MyHandler.New,MyHandler"/>
     </httpHandlers>
   <system.web>
<location path=".">
	<xhtmlConformance mode="Legacy"/>

</location>
<location path="NewFrontController.aspx">
	<xhtmlConformance mode="Transitional"/>
</location>
</configuration>

This led to proper functioning of the UpdatePanel.

Advertisements

For the past few years while interacting with developers in the .NET community I have seen that they are very much conversant with language (C#) and ASP.NET features.But very few of them has a clear idea about idea about how IIS works and the ASP.NET Request Pipeline.So in this blog and subsequent blogs I will covering some key aspects of II6.0 and ASP.NET Request processing model.

IIS Web Site

The first important unit of IIS 6.0 Infrastructure is the IIS Web Site.A IIS Web Site is configured to listen to incoming HTTP requests

By default IIS created an web site named Default Website and configured to listen on port 80.Additional sites can be configured using the IIS Administration tool.

IIS Virtual Directory

Every IIS Website maps to a physical folder in the server.The Default Website maps to C:\Inetpub\wwwroot folder by default.A virtual directory within a site is a container of files and defines a child URL space within the website e.g. If we create a virtual directory called Chat within the website www.xyz.com then it can be accessed as http://www.xyz.com/Sales .We can map this virtual directory to a physical folder named D:\Chat in the server.

IIS Application or Virtual Application

In IIS 6.0 the terms application and virtual directory is bit confusing and is found to be used interchangeably in many tech articles.An application can be considered as a virtual directory with a additional properties like Application Name,Application Root(Starting Point),Application Pool ID.The Web Site by default is associated with an application even if the above mentioned properties are not specfically set.An application should have at least one virtual directory.It can also have more than one virtual directories.e.g The WebSite www.xyz.com can contain a virtual directory as well as application named Chat (www.xyz.com/Chat) and within the application Chat there can be another virtual directory Messages (http://www.xyz.com/Chat/Messages).  This virtual directory may not be an application .

 Application Pool

An application pool is a mechanism to group and isolate a set of web applications hosted by the IIS server.Each web application is assigned to one application pool.Each application pool runs in the different instance of the worker process(w3wp.exe).e.g. there is WebApp A assigned to AppPool AP1 and WebApp B assigned to App Pool AP2 then WebApp A and B runs in two seperate processes executing different instances of w3wp.exe.This ensures better application isolation and protection i.e. failure of any one the applications will not hamper the execution of the other.Application Pool identity is the identity under which the application pool worker process executes.By default this is the network service account.This can be changed and configured using the IIS Admin Tool.The other important configurations include the application pool health monitoring and worker process recycling.The details are provided in IIS documentation http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/f05a7c2b-36b0-4b6e-ac7c-662700081f25.mspx?mfr=true