01
URL Rewriting in ASP.Net
Steps for Implementing URL Rewriting in ASP.Net
1. Create a new page in ASP.Net eg: ‘Page1.aspx ‘
2. Draw a new button and label in the page.
3. Write “Welcome to Page 1” in the label and ‘Goto to Page 2’ in the button text.
4. Similarly create second page and use the same procedure as mention above.
5. Write the below code in Page 1 command button event
Response.redirect(“practice_in_C#.aspx?ptype=1”) where ptype is page type.
6. similarly
Response.redirect(“my_first_practice.aspx?ptype=2”) where ptype is page type.
7. We need to read the querystring data (ptype) and display the page accordingly.
8. Write the below code in Global.asax
void Application_BeginRequest(object sender, EventArgs e)
{
//url rewriting for SEO
string strCurrentPath;
int intPageType = 0;
strCurrentPath = Request.Path.ToLower();
if (Request.QueryString["ptype"] != null)
{
intPageType = Convert.ToInt16(Request.QueryString["ptype"]);
}
switch (intPageType)
{
case 1:
{
Context.RewritePath(”page1.aspx”);
break;
}
case 2:
{
Context.RewritePath(”page2.aspx”);
break;
}
}
}
9. Now test the page, by running the file Page1.aspx and click on command button.
If you need to process the HTML extension file ( eg : ‘my_first_practice.html?ptype=1’ ) below are the steps you need to follow
- Goto IIS
- Open the proper box by right clicking on the virtual directory.
- Click on Configuration button
- Click on Add button from the Application Mapping Window.
- Write the path ‘C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll’ in the Executable textbox :
- Write ‘.html’ in the Extension textbox.
- Make sure the checkbox ‘Check that file exist’ is unchecked.
- Click on OK.
Its done… Enjoy !!!!!

There are no comments.