I used the method below in the EndRequest
method from global asax
. I get a HTTP 404 error
even from image request or other requests. The point is that I want to check only for the first request/main request. Can you help me please. This is the only solution that works.
{
if (Context.Response.StatusCode == 404)
{
Response.Clear();
var rd = new RouteData();
rd.DataTokens["area"] = "AreaName";
rd.Values["controller"] = "Errors";
rd.Values["action"] = "NotFound";
IController c = new ErrorsController();
c.Execute(new RequestContext(new HttpContextWrapper(Context), rd));
}
}