Monday, August 20, 2007

URL Re-writing in a simple way.

Most of the times we have to write the Module or handler for the URL Re-Writing we also have to mark its registration in the web.config file but there also a simple way to achieve it.

Below is the code snippet from the Global.asax file.

protected void Application_BeginRequest(object sender, EventArgs e)
{
try
{
HttpContext myContext = HttpContext.Current;
myContext.RewritePath(Request.QueryString["PageName"].ToString());
}
catch (Exception ex)
{
Response.Write("ERR in Global.asax :" + ex.Message + "\n\n" + ex.StackTrace.ToString() + "\n\n");
}
}

No comments: