http://yourdomain.com/imran
http://yourdomain.com/knowledge
http://yourdomain.com/world
If you want to achive this functionality then you have to use third party ISAPI module or IIS 6.0 Wildcard mapping feature.
If you goes with ISAPI module, then you should have dedicated server to install that module. And with the other approch of IIS 6.0 Wildcard mapping, its created the proformance problem, as each and every request it tries to apply mapping and degrade the performance.
So in this case the following solutions is good and easy.
What if you made request to a page which out extension? Yes, you will get HTTP 404 page, and IIS are not automatically forward your request to ASP.NET; we can't serve the URL.
So here is the solution,
- Configure the IIS so that; each 404 error page should get redirect to an ASPX page.
- Write the few lines of .NET code.
Thats it.
Lets see how we can do this.
Step 1: Configure IIS for redirection
Step 2: Write the .NET code
You have to capture Application_BeginRequest and put the specilized code to grab 404 url.
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Request.Url.ToString().Contains("404;"))
{
string[] urlInfo404 = Request.Url.Query.ToString().Split(';');
if (urlInfo404.Length > 1)
{
string strRequestUrl = urlInfo404[1].Replace(":" + Request.Url.Port + "/", "/");
//You got the URL now take action on it.
}
}
}
Benefits:
- No third party ISAPI module
- No Wildcard mapping; leads to good profermance.
More on this article? Read the ScottGu's Blog on Tip/Trick: Url Rewriting with ASP.NET.
No comments:
Post a Comment