0

In my web.config I have the following:

<customErrors mode="Off" defaultRedirect="~/error" redirectMode="ResponseRewrite">
  <error redirect="~/error" statusCode="404" />
  <error redirect="~/error" statusCode="500" />
</customErrors>
...
<httpErrors errorMode="Custom">
  <clear />
  <remove statusCode="404" />
  <remove statusCode="403" />
  <remove statusCode="401" />
  <error statusCode="404" path="~/Error" responseMode="ExecuteURL" prefixLanguageFilePath="" />
  <remove statusCode="500" />
  <error statusCode="500" path="~/Error" responseMode="ExecuteURL" prefixLanguageFilePath="" />
</httpErrors>

In my global.asax I have the following:

protected void Application_Error(object sender, EventArgs e)
    {
        // Do whatever you want to do with the error

        //Show the custom error page...
        //Server.ClearError();
        RouteData routeData = new RouteData();
        routeData.Values["controller"] = "Error";

        Exception exception = Context.Server.GetLastError();
        if (exception != null && !ExceptionUtilities.IsExceptionIgnored(exception))
            ErrorSignal.FromCurrentContext().Raise(exception);

        Server.ClearError();

        HttpException httpException = Context.Server.GetLastError() as HttpException;
        if (httpException != null && ((Context.Server.GetLastError() is HttpException) && (httpException.GetHttpCode() != 404)))
        {
            routeData.Values["action"] = "Index";
        }
        else
        {
            // Handle 404 error and response code
            Response.StatusCode = 404;
            routeData.Values["action"] = "NotFound";
        }
        Response.TrySkipIisCustomErrors = true; // If you are using IIS7, have this line
        IController errorsController = new ErrorController();
        HttpContextWrapper wrapper = new HttpContextWrapper(Context);
        RequestContext rc = new System.Web.Routing.RequestContext(wrapper, routeData);
        errorsController.Execute(rc);
    }


}

When I navigate to http://localhost:56469/sss I get the custom error page I created for this. However when I navigate to http://localhost:56469/sss. (note the period) I get the ugly yellow IIS screen stating The resource cannot be found.

What do I need to do to cover this "flavor" of 404?

halfer
  • 19,824
  • 17
  • 99
  • 186
SB2055
  • 12,272
  • 32
  • 97
  • 202
  • Have you tried adding `` to your web.config? – DavidG May 01 '17 at 01:38
  • @DavidG - yes, same results. – SB2055 May 01 '17 at 02:05
  • Please do not add voting/closure commentary into questions themselves. It is better to do it in comments anyway, since the handle is more likely to ping the closer here than in your post. – halfer May 01 '17 at 07:54
  • For @Nkosi, from the OP: I appreciate your vigilance here but I'm asking to handle the error appropriately, not to ignore the `.`. Please revoke your flag asap as it is erroneous. – halfer May 01 '17 at 07:55
  • @SB2055. I recreated your problem with the [mcve] provided. In looking for a solution I came across the duplicated question Something you are suppose to do before asking already asked questions. Applying the answer handled the error which indicated to me that this question was in fact a duplicate of the stated post. – Nkosi May 01 '17 at 09:47

0 Answers0