R – url routing doesn’t work when publishing to another server

asp.netasp.net-3.5iis-6url-routing

I've implemented url routing with the following rule:

    string virtualPath = "~/" + requestContext.RouteData.Values["page"].ToString();

    //if virtualpath doesn't end in aspx, then it's just a directory path loading
    //default.aspx by default.
    if (!virtualPath.EndsWith(".aspx") && !virtualPath.EndsWith(".txt"))
    {
        virtualPath += "default.aspx";
    }

    return BuildManager.CreateInstanceFromVirtualPath(
            virtualPath, 
            typeof(Page)) as Page;

This works perfectly fine as long as it's on my development machine running under asp.net development server.

For example, the following url: localhost:3328/en/Products/
will load default.aspx located under /Products/
/en/ directory obviously doesn't physically exist.

However it'll fail to load when publishing to qa.mysite.com
so it'll fail when going qa.mysite.com/en/Products
It gives the 404 page not found.

it works if I go qa.mysite.com/en/Products/default.aspx

So it's not really url routing that's not working, I'm thinking it's some settings? I'm running iis6.

Best Answer

Trick is IIS6 won't be executing the asp.net pipeline by default, so that call to /en/products/ goes to the IIS 404 error without ever giving your routing a chance to fire off.

What you need to do is either use a wildcard mapping (many shared hosts and network admin types won't like this) or use the old "set 404 page to use an asp.net to capture all requests" trick. Wildcard is the better option, especially with routing. I haven't tried the 404 trick there, but in principal it should work.

Related Topic