指向404上的自定义错误页面由带有'。'的URL触发最后

时间:2017-05-01 01:35:03

标签: c# .net asp.net-mvc

在我的web.config中,我有以下内容:

<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>

在我global.asax我有以下内容:

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);
    }


}

当我导航到http://localhost:56469/sss时,我收到了为此创建的自定义错误页面。但是当我导航到http://localhost:56469/sss.时(注意句号),我会看到丑陋的黄色IIS屏幕,说明The resource cannot be found.

我需要做些什么才能涵盖404的这种“味道”?

0 个答案:

没有答案