0

While trying to figure out why the Global.asax would not work, I decided to move onto Custom Errors and started running into problems there. I am testing the 404 (Page not found) and it keeps giving me the standard server error page rather than my own page.

I tried setting it on the IIS side of things and that did not work. In fact, having the settings match seemed to throw more errors. I have removed that change to return it to the current issue. I have provided the changes I made to make this error page. Perhaps someone brighter than me can figure out what went wrong?

<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Error.aspx" />

Any help is widely appreciated! I did check to see if the Error.aspx exists and it does so I know it is not an actual 404 page not found issue

EDIT: Tried suggested duplicate answers and it did not work

EDIT 2: This is the error that appears on the screen

HTTP Error 404.0 - Not Found

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Most likely causes:

  • The directory or file specified does not exist on the Web server.
  • The URL contains a typographical error.
  • A custom filter or module, such as URLScan, restricts access to the file.

Things you can try:

  • Create the content on the Web server.
  • Review the browser URL.
  • Check the failed request tracing log and see which module is calling SetStatus. For more information, click here.

Detailed Error Information:

Module IIS Web Core

Notification MapRequestHandler

Handler StaticFile

Error Code 0x80070002

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Jeremy Beare
  • 489
  • 3
  • 8
  • 22

1 Answers1

-1

I recommend you to use a Controller to specific for this, for example:

[AllowAnonymous]
    public class ErroHttpController : Controller
    {
        [Route("RequestError")]
        public ActionResult RequestError()
        {
            Response.StatusCode = 400;
            return View();
        }

        [Route("NotFound")]
        public ActionResult NotFound()
        {
            Response.StatusCode = 404;
            return View();
        }

        [Route("InternalError")]
        public ActionResult InternalError()
        {
            Response.StatusCode = 500;
            return View();
        }

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            Response.TrySkipIisCustomErrors = true;
            base.OnActionExecuting(filterContext);
        }
    }
}

And in your web.config you should do:

<customErrors mode="RemoteOnly">
      <error statusCode="400" redirect="/RequestError"/>
      <error statusCode="404" redirect="/NotFound"/>
      <error statusCode="500" redirect="/InternalError"/>
</customErrors>

You must skip IIS custom errors, like the code above, in OnActionExecuting method.

Pedro Benevides
  • 1,970
  • 18
  • 19