Still unclear about using RewritePath for a default page

I read Scott W.'s article on URL rewriting in .Text, and it's pretty straight forward. What I'm still not getting is how you can handle a default page request without having to wildcard map requests in IIS. For example, in this very blog, you can request "/Jeff" or "/Jeff/" and get my blog. I assume that's because IIS and ASP.NET are assuming this is a request for "/Jeff/default.aspx," but perhaps I'm not seeing something right. I've been looking at the .Text code and it's not entirely obvious to me.

Anyone wanna help a guy out?

8 Comments

  • Hey Jeff,



    I have rewritten most of the "map all" code used in .Text a couple times over the last year. I think I have it as simple as it is going to get and I will republish it after my talk on the subject at VSLive in February.



    In the current version of .Text, I do a quick check to see if the requested url ends in .aspx, if not, I substitute "default.aspx"



    public static IHttpHandler GetHandler(HttpContext context, string requestType, string url, string path)

    {

    if(!path.ToLower().EndsWith(".aspx"))

    {

    path = System.IO.Path.Combine(path,"default.aspx");

    }

    return PageParser.GetCompiledPageInstance(url, path, context);

    }



    HTH,

    Scott

  • That's the primary question I have... If a "/" request is made, is IIS trying default.aspx? In the testing I've done, I don't think it is, but as I mentioned to Scott in e-mail, I don't recall having to set a wildcard mapping in IIS to make .Text work for multiple blogs (thus the question about /Jeff or /Jeff/ working here).



    Scott hasn't written back yet, but it's the weekend and it's not like any of us are paying him. :)



    One thing I will say about using IHttpHandlerFactory is that it's a lot less messy than using RewritePath and overriding the page's Render method to fix the form action attribute.

  • When you use wildcard mappings, default documents no longer work...which is why you need to use code similar to what I posted above.



    You do not have to set up wildard mappings in the multi-blog setup..however, you need an empty default.aspx fle in the "/jeff" folder...otherwise, asp.net will never handle the request.



    -Scott

  • OK... you've got me stumped there. Why does it work on this site? There isn't a physical folder for every single user, is there?

  • Jeff, it is a simple mapping from *.* extension in the IIS file mappings to the ASP.NET ISAPI DLL. That way, ASP.NET is capable of picking up the tab... and you are able to rewrite any given URL to anything you want.

  • Ugh... I know that. I've known that since 2001. But Scott says it's not necessary in .Text. Again, how can IIS send the requests for /jeff and /jeff/ to ASP.NET then?

  • If you use such a wildcard mapping in IIS, the ASP.NET runtime will handly *all* requests, including the /jeff and /jeff// requests. Scott must be either using such a wildcard mapping, or he must be using physical directories for each user (heh).

  • Scott confirmed via e-mail that he does indeed wildcard for the bigger sites. That's what I was after. I figured that was the case but wanted to make sure I wasn't missing something obvious.

Comments have been disabled for this content.