Reputation: 33
I would like my website to create search-engine-optimized links for dynamic content (instead of locating data via the querystring). So:
mysite/SomeModifiableNname.aspxinstead 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.
Upvotes: 1
Views: 1049
Reputation: 33
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.
Upvotes: 0
Reputation: 89102
I've done this in the past with UrlRewrite.Net. There is also a built in facility for this in IIS7
Upvotes: 0
Reputation: 953
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.
Upvotes: 2