I'm developing new web site in asp net mvc 5. And I want to create custom 404 page where users who tried to access old url will be redirected. The problem is that I want to create view for this error page and take parameters from url trying to identify what product users tried to access. But I haven't found solution how to create it. All examples with editing webconfig like this:
<defaultRedirect="~/Errors/NotFound" mode="Off">
<error statusCode="404" redirect="~/Errors/NotFound" />
</customErrors>
will not pass parameters. I tried to disable custom errors and make changes in Global.asax :
public void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
Response.Clear();
HttpException httpException = exception as HttpException;
if (httpException != null)
{
if(httpException.GetHttpCode() == 404)
{
var rd = new RouteData();
rd.Values["controller"] = "Errors";
rd.Values["action"] = "NotFound";
rd.Values.Add("queryString", HttpContext.Current.Request.Url.AbsolutePath);
IController c = new ErrorsController();
c.Execute(new RequestContext(new HttpContextWrapper(Context), rd));
}
}
}
But it still returns standart error page