Question

I want to redirect custom error page with the visited custom error url

So for example lets say i have visited

http://stackoverflow.com/myOwnError

Now i want visitor to still land this page. But when this page getting loaded i should tell browser it is error 404

And i also need to be able to grab url itself myOwnError

I suppose the below code at custom error page load would tell 404 code to browser

protected void Page_Load(object sender, EventArgs e)
{
    Response.StatusCode = 404;
}

How can i do this ?

asp.net 4.5 , II8

Était-ce utile?

La solution

You need to to add the customErrors section in the web.config file and turn on custom errors. Add an error element for HTTP status code 404 (resource not found). The following markup shows an example.

.

By doing this you will not need to write code to tell the browser that it is a "404 Error", and you can still write your own code in your custom error page, that is you can retrieve the url and etc..

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top