I have a c# web application on i.e. http://mysite.com
User opens his browser and types http://mysite.com/anywrongpath
Which I want to do is to get the “exact” url ( /anywrongpath ) and THEN redirect that user to i.e. /MainPage.aspx
I think I can handle redirection with:
protected void Application_Error(object sender, EventArgs e)
{
HttpException httpException = Server.GetLastError() as HttpException;
if (httpException.ErrorCode == 404)
Response.Redirect("/MainPage.aspx");
}
However, I have no idea how to handle the retrieve process of typed url. I made a research of “Sessions” , “Request.ServerVariables” , “Request.Url” etc but I couldnt solve the problem.
I am open for any idea how to solve it, and really glad if you give tiny code samples, thanx
Murat
Edit your web.config file and put something like this in the
system.websectionWhen your user types an address like mysite.com/non-existant, IIS redirects him to
mysite.com/MainPage.aspx?aspxerrorpath=/non-existantThis way, you can get the
Request.QueryString["aspxerrorpath"]