Introduction
Sometimes, we want that our web url will not contain any
"?","&" or other kind of non readable symbols, but the question is
that how to remove them from the browser's address bar, but that
information is very essential for us because they are query parameters
for us. So it is like we are hiding information of query string
from the user by displaying some nice and readable contains, but with
at server side we want our query parameters back. So that is called
"URL rewriting". Don't worry it is not a difficult task.
Background
Before that, we have to have some knowledge of how the requests
are processed on ASP.NET server? Remember that when any request is
coming it has to pass through "Application_BeginRequest()" method in Global.asax file.
This is that access point of each and every requests those are coming
to our application.So cheers it is that point where we have to work for
URL rewriting.
Using the code
1. First we have to add "Global.asax" file into our application.
void Application_BeginRequest(object sender, EventArgs e)
string absoluteUrl = Request.Url.AbsolutePath.ToString();
if (absoluteUrl.Contains("/test/default.aspx"))
{
string pageid = absoluteUrl.Substring
(absoluteUrl.LastIndexOf('/') + 1).Trim();
pageid = pageid.Substring(6);
string path = "~/test/default.aspx?mypageid=" + pageid;
Response.Redirect(path);
So it is really a simplest way to rewrite the URL isn't it?
Points of Interest
I like to Share my knowledge with guys like you,
because i am also one of you, that if i dont know anything then i come
to you...so keep exchange of knowledge...
History
keep attached with my simple way series articles....
Chirag Patel, a Programmer Analyst in a well known IT company working on .NET Technologies since last 2 years. He is interested in Pure business logic and fuzzy logic. his area of interest is in C#.NET, VB.NET and MSSQL 2005.
catch me on: http://groups.google.com/group/codewar