views:

341

answers:

6

I would like my website to create search-engine-optimized links for dynamic content (instead of locating data via the querystring). So:

mysite/SomeModifiableNname.aspx
instead of

mysite/DynamicContent.aspx?entryID=2345
.

Aside from a smart 404 handler that redirects requests, or a custom mime-type handler in IIS, is there a good solution for this in ASP.NET?
Keeping in mind that the page file name must be able to be changed at run-time.

+3  A: 

You can use a HttpHandler, as seen here.

Larsenal
+2  A: 

this is a broad topic generally referred to as URL rewriting...

there are several ways to accomplish this. I would suggest looking into the IIS Rewrite Module.

You should probably also investigate the URL routing capabalities that were developed for MVC and are available in ASP.NET 3.51

UPDATE: I wish I knew more about your intentions. That last sentence confuses me.

alex
A: 

I've done this in the past with UrlRewrite.Net. There is also a built in facility for this in IIS7

Jason
A: 

Thanks for everyone's thoughts. With the information provided, I came across what I think is the solution I need:

In the Global.asax (or via an HttpModule), listen to the BeginRequest event and apply Context.Rewrite path there:

void Application_BeginRequest(object sender, EventArgs e)
{
    string fullOrigionalpath = Request.Url.ToString();

    if (fullOrigionalpath.ToLower().Contains("/Games".ToLower()))
    {
        Context.RewritePath("Default.aspx?id=Games");
    }

}

And then, on the OnPreInit method of the page that will handle these requests, Rewrite path needs to be applied again so that PostBacks will work appropriately:

protected override void OnPreInit(EventArgs e)
{
    base.OnPreInit(e);

    if (Request.QueryString["id"] == null)
        return;
    if (Request.QueryString["id"].ToLower().Equals("games"))
        Context.RewritePath("Games", "", "id=Games");
}

The key that makes this work better than a lot of URL-rewriting modules I came across is that the paths can be dynamic. That is, the created URLs can be data-driven.

Colin
A: 

Use ASP.NET MVC.

GeekyMonkey