Search code examples
asp.netroutes.net-4.0url-routing

Deploying ASP.NET 4 Web Forms Application Using Routing on IIS 6


To clarify, the scenarios I am looking at involve deploying ASP.NET 4 Web Forms application that employ RouteTable.Routes.MapPageRoute:

public class Global : System.Web.HttpApplication
{
  public static void RegisterRoutes(RouteCollection routes)
  {
    RouteTable.Routes.MapPageRoute("questionnaires", "questionnaires", "~/Pages/Questionnaires/List.aspx", false);
    RouteTable.Routes.MapPageRoute("questionnaires_submit", "questionnaires/submit", "~/Pages/Questionnaires/Insert.aspx", false);   
  }

  void Application_Start(object sender, EventArgs e)
  {
    RegisterRoutes(RouteTable.Routes);
  }
}

Scenario 1: The application is NOT hosted as a virtual directory in an existing website, but is a stand-alone website (it is its own starting point). It has its own application pool. When deployed, it worked without any tinkering.

Scenario 2: The application is hosted as a virtual directory underneath an existing website. It also has its own application pool. However, I received 404 errors when trying to access the routes I had mapped out. Fortunately, I had experience getting MVC to work in 3.5 sp 1, so I tried that method: opened the properties dialog of the virtual director, went to the "Directory" tab, click the "Configuration" button, and added a Wildcard application map to the aspnet_isapi.dll and unchecked the "Verify that file exists" checkbox. This made it work.

My question is why did I have to add a wildcard application map in the second scenario but not the first? If it helps, the root website that hosts the virtual directory in the second scenario is set up with ASP.NET version 2.0.50727.


Solution

  • ASP.NET 4.0 Enables Routing of Extensionless URLs In ASP.NET v4.0, there is a better way to enable routing. Normally you're only interested in routing extensionless URLs, and have no need to route static requests (HTML, JPG, GIF, CSS, JS, etc). In v4.0 there is a new feature that allows extensionless URLs to be directed into managed code, without impacting static requests (HTML, JPG, GIF, CSS, JS, etc). Because of this feature, on IIS 6 you no longer need a wildcard mapping

    See here for more info:

    MSDN

    Essentially, the .NET 4.0 routing dll is smarter than the 3.5 version. As a result, less work arounds. In your case, you probably have the standalone site running in full .NET 4.0 whereas in your virutal directory, the root is running under 2.0/3.0/3.5 mode. Hope this helps!