How Do URLs to Entries Work?

Nov 20, 2008 at 8:39 PM
Okay, I've been programming many, many years. But I'm still relatively new to ASP.NET. Can anyone explain to me exactly how the links to posts work? (NOTE: I'm currently storing my data in a SQL Server database.)

For example, the link to one of my blogs has the URL http://(domain)/post/2008/11/19/Power-Switches-and-Other-Annoyances.aspx. But this folder or aspx file doesn't really exist. Can anyone clarify for me how this is working exactly. Again, my data is being stored in a database and not XML files.

I plan to dig into the source a bit. But a bird's eye view of what is happening would save me some time.

Nov 20, 2008 at 8:59 PM
There's at least 2 places where these virtual URLs are being handled.

One place is the Web.Config file.  In the httpHandlers section, you'll see that specific filenames (that don't really exist) are being handled by the specified handlers.  Examples are file.axd, image.axd, syndication.axd.  As defined in the web.config file, these map to the FileHandler class, ImageHandler class and SyndicationHandler classes respectively.  These classes implement the IHttpHandler interface and are in the BE Core under Web -> HttpHandlers.

The other place virtual URLs are handled is in the UrlRewrite.cs file in the BE Core under Web -> HttpModules.  In the context_BeginRequest() method, specific patterns in the URL are being searched for.  This includes the blog post URL you asked about.  If a match is found, the RewritePath() method is called to change (or rewrite) the URL to an actually existing page.  The rewritten URL is only seen during the processing of the request on the server -- IOW the client doesn't see the rewritten URL.  For your blog post example, the URL is rewritten so the post.aspx page handles the request with the post ID tacked on as a querystring parameter.
Nov 21, 2008 at 12:07 AM
Okay--thanks for the overview.

If that works out as I'm thinking, then I really like it because it seems like it would be very search-engine friendly, behaving as those blog entries are really separate files.

Thanks again.