Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

IIS 7 deployment: ASP.NET 4.0 Routing and Ext.NET

0.00/5 (No votes)
3 Dec 2011 1  
How to: ASP.NET 4.0 Routing and Ext.NET.

Introduction

A few days ago, I got a problem during the deployment of an ASP.NET 4.0 website on IIS7 with default app pool. The website includes ASP.NET 4 routing features and ext.net in the website. But when I tried to access the ext.net enabled pages, I found nothing over there, just a blank page. The configuration was as follows:

Setup and Configuration 

For ext.net install and setup, I used the following steps for Visual Studio 2010 SP1:

  1. To start, you will need to download the Ext.Net latest version from http://www.ext.net/.
  2. Unzip the contents of the zip file into a new directory.
  3. Open the directory and copy the following five files to your project's /bin directory:
    1. Ext.Net.dll
    2. Ext.Net.Utilities.dll
    3. Ext.Net.xml
    4. Newtonsoft.Json.dll
    5. Newtonsoft.Json.xml
  4. In Solution Explorer, make sure the View All Files button is selected.
  5. Expand the /bin directory to display all files and click the Refresh button at the top.
  6. Select each of the new files you just added to the /bin directory (shift + click).
  7. Right click and choose “Include in Project”.
  8. In Solution Explorer, click the Properties button for your project (top left button).
  9. Click on the References tab on the left. You should see all the references in the center.
  10. Click the Add button and then the Browse tab.
  11. Browse to your project's /bin directory (where you copied the DLLs to) and select the three DLLs and click OK.
  12. Under Imported namespaces, scroll to the bottom and click on the checkboxes for the following:
    1. Ext
    2. Ext.Net
    3. Ext.Net.Utilities
    4. Newtonsoft
    5. Newtonsoft.Json
  13. Open your web.config file. You will need to add the following to your config file:
XML
<configuration> 
<section name="extnet" type="Ext.Net.GlobalConfig" requirePermission="false" />
<configSections>
<system.web>
<httpHandlers>
<add path="*/ext.axd" verb="*" type="Ext.Net.ResourceHandler" validate="false" />
</httpHandlers>
<httpModules>
<add name="DirectRequestModule" type="Ext.Net.DirectRequestModule,Ext.Net" />
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="DirectRequestModule" preCondition="managedHandler"
type="Ext.Net.DirectRequestModule, Ext.Net" />
</modules>
<handlers>
<add name="DirectRequestHandler" verb="*" path="*/ext.axd" 
  preCondition="integratedMode" type="Ext.Net.ResourceHandler" />
</handlers>
</system.webServer>

Now follow the steps to add Ext.Net in your Visual Studio toolbox:

  • Open a .aspx file to exit in Visual Studio. We do this so items are displayed within your toolbox (if it is a .vb, .cs, etc., it will not display items).
  • Next click on your toolbar and click Add tab. Name this tab something (Ext.Net).
  • Right click under this tab and click Choose Items.
  • Click the Browse button under “.NET Framework Components”.
  • If no errors are displayed, you should now see all the components under the new tab.

Before you begin, I would suggest doing a Build Clean and Rebuild to confirm all the new changes are set. To use Ext.Net within your page requires two changes to an existing page: a register tag and the resourcemanager tag.

At the top of your page (under the page directive), add the following which will give you access to the Ext.Net DLL:

ASP.NET
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

Next find your BODY tag and add the following:

ASP.NET
<ext:ResourceManager ID="ResourceManager1" runat="server" />

And for routing: configure an ASP.NET website or web application for routing. You first need to add a reference to the System.Web.Routing assembly. The SP1 installation for .NET Framework 3.5 will install this assembly into the Global Assembly Cache, and you can find the assembly inside the standard “Add Reference” dialog box. You’ll also need to configure the routing module into the ASP.NET pipeline. The routing module is a standard HTTP module. For IIS 6.0 and earlier, and for the Visual Studio web development server, you install the module using the <httpModules> section of web.config, as you see here:

XML
<httpModules>
<add name="RoutingModule"
  type="System.Web.Routing.UrlRoutingModule,
        System.Web.Routing,
        Version=3.5.0.0, Culture=neutral,
        PublicKeyToken=31bf3856ad364e35″/>
</httpModules>

URL rewriting implementations typically perform their work during the BeginRequest event, which is the earliest event to fire during a request. With URL routing, the route matching and selection of a route handler occurs during the PostResolveRequestCache stage, which is after the authentication, authorization, and cache lookup stages of processing. I will need to revisit the implications of this event timing later in the column.

To run a web site with routing in IIS 7.0, you need two entries in web.config. The first entry is the URL routing module configuration, which is found in the <modules> section of <system.webServer>. You also need an entry to handle requests for UrlRouting.axd in the <handlers> section of <system.webServer>. Both of these entries are as follows:

XML
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule"
type="System.Web.Routing.UrlRoutingModule,
System.Web.Routing, Version=3.5.0.0,
Culture=neutral,
PublicKeyToken=31BF3856AD364E35″ />
</modules>
<handlers>
<add name="UrlRoutingHandler"
preCondition="integratedMode"
verb="*" path="UrlRouting.axd"
type="System.Web.HttpForbiddenHandler,
System.Web, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
</system.webServer>

The runAllManagedModulesForAllRequests attribute requires a value of true if you want to use the extensionless URLs as I’ve done in this sample. Also, it might seem strange to configure an HTTP handler for UrlRouting.axd. This is a small workaround that the routing engine requires in order for routing to work under IIS 7.0. The UrlRouting module actually rewrites the incoming URL to ~/UrlRouting.axd, which will rewrite the URL back to the original, incoming URL.

Problem

The problem was ext.net worked fine after removing routing related code from the site. But we need both of them to work together.

Then we we tried to find a workaround for that problem and got a few links on Google, we compiled them and applied them one by one and finally we got the solution to use both of them together.

Solution

The solution is as follows:

  • Remove httpHandlers and httpModules from system.web
  • Configure system.webServer like below:
  • XML
    <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
    <add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net"/>
    </modules>
    <handlers>
    <add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net"/>
    </handlers>
    </system.webServer>
  • Configure global.asax
  • C#
    RouteTable.Routes.Ignore("{resource}.axd/{*pathInfo}");
    RouteTable.Routes.Ignore("admin/{*pathInfo}");
    // this is because I used the ext.net in the admin module 

That was all and the website is running without any conflict.

The reasons we use ext.net

  1. It has a *simple* design model that is followed consistently throughout the code.
  2. The upgrade path from v.0.33 to v.1.1 to v.2.02 was smooth and mostly uneventful (i.e., it worked as it should!) with the exception of the grid component that was really a hard nut to crack (for the upgrades that is).
  3. Flexibility over choosing the best combination of extsjs+glue+custom code or full extsjs+custom code. For example, for a long time, although I used extjs for almost everything, I relied on YUI’s XHR calls for actually doing AJAX stuff and it worked like a charm.
  4. Excellent UI with a lot of really helpful examples.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here