Quantcast
Channel: All Forums
Viewing all articles
Browse latest Browse all 27852

IIS 7.5 URL rewrite module and URL routing in Global.asax for sub-applications

$
0
0

I have a "top-level" web-site, www.ccesd.ac.uk, and various "lower-level" web-sites running off it such aswww.ccesd.ac.uk/BritSocAt that are separate sites but share a lot of code.  These lower-level sites are specified as web applications in IIS 7.5 and inherit a common web.config file fromwww.ccesd.ac.uk, although they live in their own application pools.

I have configured IIS 7.5 with the URL Rewrite module so that the lower-level sites can have their own distinct URLs, e.g. www.BritSocAt.com, which maps to www.ccesd.ac.uk/BritSocAt.

Site configuration in IIS 7.5

Each site has its own Global.asax file with URL routing rules defined for pretty URLs.  These URLs (/Home, /About, /Contact etc.) are common to all sites, including the top-level (ccesd.ac.uk) site.

void Application_Start(object sender, EventArgs e)
    {
      // Code that runs on application startup
      RegisterRoutes(System.Web.Routing.RouteTable.Routes);
    }

    // ** URL ROUTING **
    private static void RegisterRoutes(System.Web.Routing.RouteCollection routes)
    {
      routes.Ignore("{resource}.axd/{*pathInfo}");
      // HOME
      routes.MapPageRoute("Home", "Home", "~/Body.aspx", false, new System.Web.Routing.RouteValueDictionary
 { { "control", "HomePage" } });
      // CONTACT US
      routes.MapPageRoute("ContactUs", "Contact", "~/Body.aspx", false, new System.Web.Routing.RouteValueDictionary
 { { "control", "CCESDContactUs" } });
      // ABOUT US
      routes.MapPageRoute("AboutUs", "About", "~/Body.aspx", false, new System.Web.Routing.RouteValueDictionary
 { { "control", "CCESDMissionStatement" } });
    }

I understand from Ruslan Yakushev's excellent tutorial that the IIS URL rewriting module is processed before the ASP.NET routing in Global.asax.  This is the way I need it to work.  However, if I typehttp://www.britsocat.com/About, I find that the Global.asax file forwww.ccesd.ac.uk is being used!  (I have verified this in testing.)  Furthermore, this takes placebefore IIS URL rewriting.  In other words, the resulting page served ishttp://www.ccesd.ac.uk/Body.aspx?control=CCESDMissionStatementinstead of http://www.ccesd.ac.uk/BritSocAt/Body.aspx?control=CCESDMissionStatement.

I suspect this is because I have the same routing rule ("About") in both sites (Global.asax files).  I think I could fix this by changing the name of the rule in one of the files; but that's undesirable in general, especially for "Home".

Is there anything I've missed or anything I can do to fix it?


Viewing all articles
Browse latest Browse all 27852

Trending Articles