views:

135

answers:

1

Hello,

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.

A: 

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.

Wyatt Barnett
perfect. Thankyou. wildcard mapping did the trick!
although there's another problem. Now it works for everything except for the root:www.mysite.com/en/there is a default.aspx that exists under www.mysite.com and indeed it works for www.mysite.com/en/default.aspx. However I get an error, and it's not 404. It's when doing the actual routing. it fails on the first line in the code when it tries to retrieve the "page" attribute from routedata values. It just crashes from object reference not found.I had read somewhere that this was an asp.net problem with the root directory. Do you have any idea about this?