For these url we can't user ASP.NET URL Re-Writing, as there is no aspx extension added to this url.
When you found such request and its not exists then IIS will give 404 error, but we need to parse such url and do some validation and give them proper output. In this case lets say I would like to see the profile of user imran, then I make request to http://mysite.com/imran/ which gives me the profile of user imran.
This is the normal requirement, we can do it easily in php and java. But in .net this is bit tricky to get such functionality working.
If we use http handler, then also we are not able to identify the request as it has no extension. As its is not reaching to the application, IIS itself reject this request, no global.ascx or web.config
I found very easy solution for this solution. This requires some setting on virtual directory and code in our system to handle such request.
As I mention eariler when you send request to http://mysite.com/imran/ which not exist; IIS will raise 404 error, what we do is, we trap this error and get the requested page or url and do some work and give the result.
In IIS we have to change default 404 error handling to aspx page, bye default 404 page is C:\WINDOWS\help\iisHelp\common\404b.htm with Message Type as File. See the image
We need to change this to forward all such request to our application, once we got control in aspx page then we can do anything on such request.
For this we need to change Message Type, set it to URL and the URL will be /MySite/Handle404.aspx. See the image
We have to write few lines of code in Handle404.aspx to handel this request.
Here we are just grabbing the trailing string, in this case its imran or armaan.
protected override void OnInit(EventArgs e)
string urlInfo404 = Request.Url.Query.ToString().Split(';');
if (urlInfo404.Length > 1)
string strRequestUrl = urlInfo404.Replace(":" + Request.Url.Port + "/", "/");
strRequestUrl = strRequestUrl.Insert(strRequestUrl.Length, "/");
string urlInfoFavAddress = strRequestUrl.Split('/');
string strUser = urlInfoFavAddress[urlInfoFavAddress.Length - 2];
Once I get the key its get redirected to Profile page, as its Server.Transfer which does not change the url.