URL Rewriting using IHttpHandler

Below Example Explains how can we Rewrite the incoming url in asp.net.

 class UrlHandler : IHttpHandler  
#region IHttpHandler Members
public bool IsReusable
get { return false; }
public void ProcessRequest(HttpContext context)
string vPath = context.Request.RawUrl;
//The hard coded value for path can be put in config file to create rules
int vIndexOfFolder = vPath.IndexOf("/users/", StringComparison.OrdinalIgnoreCase);
if (vIndexOfFolder > 0)
string vUserName = vPath.Substring(vIndexOfFolder + 7);
//remove .aspx extension
vUserName = vUserName.Substring(0, vUserName.Length - 5);
context.Response.Write("Welcome " + vUserName+" "+"Click here to continue");

Published by Nirbhay

Technology Geek,Blogger,Reviewer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: