部署到IIS 7.5后的空白自定义404页 [英] Blank custom 404 page after deploying to IIS 7.5

查看:197
本文介绍了部署到IIS 7.5后的空白自定义404页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不正确的网址,如的http://本地主机:54321 /富/栏和错误,如 HttpNotFound()在我的本地主机没有问题的处理。部署到IIS 7.5后,对上述两个方案中返回一个空白页。我见过别人有这个问题,这里(这是一个从Moulde与几个upvotes注释)。在code:

Incorrect urls like http://localhost:54321/foo/bar and errors like HttpNotFound() are handled in my localhost without problems. After deploying to IIS 7.5, it return a blank page on both of the above scenarios. I've seen someone else had this problem Here(It was the comment from Moulde with several upvotes). The code:

的Web.Config

<system.web>
  <customErrors mode="Off" redirectMode="ResponseRedirect">
    <error statusCode="404" redirect="~/Error/NotFound"/>
  </customErrors>
</system.web>
<httpErrors errorMode="Custom" existingResponse="Replace">
  <remove statusCode="404" />
  <error statusCode="404" responseMode="ExecuteURL" path="/Error/NotFound"/>
  <remove statusCode="500" />
  <error statusCode="500" responseMode="ExecuteURL" path="/Error/Error"/>
</httpErrors>

ErrorController

public class ErrorController : Controller
{
    public ActionResult NotFound() {
        Response.StatusCode = 404;
        Response.TrySkipIisCustomErrors = true;
        return View();
    }
}

RouteConfig

 routes.MapRoute(
            "Error - 404",
            "NotFound",
            new { controller = "Error", action = "NotFound" }
            );

        routes.MapRoute(
            "Error - 500",
            "Error",
            new { controller = "Error", action = "Error" }
            );
        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

NOTFOUND

<h2>404 Not Found</h2>
<div class="alert alert-info">
    <p><strong>Whoops...</strong></p>
    <p>The resource you were looking for doesn't exist</p>
</div>

服务器运行Windows Server 2008 R2。当我去... /富/酒吧或一个动作返回 HttpNotFound(),它返回一个空白页。任何想法?

The server runs Windows Server 2008 R2. When I go to .../foo/bar or an action returns HttpNotFound(), it returns a blank page. Any idea?

首页/测试

public class HomeController: Controller{
    // ...
    public ActionResult Test(){
        return HttpNotFound();
    }
}

更新:
当我去 /错误/ NOTFOUND 在服务器上,它返回一个空白页,以及与404与小提琴手的响应:

Update: When I go to /Error/NotFound on server, it returns a blank page as well with 404. The response with Fiddler:

HTTP/1.1 404 Not Found
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5 
X-AspNetMvc-Version: 5.2
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?  QzpccWhlXFByb2plY3RzXFZlbmRvclBvcnRhbFxWZW5kb3JQb3J0YWxcRXJyb3JcTm90Rm91bmQ=?=
X-Powered-By: ASP.NET
Date: Thu, 23 Apr 2015 13:24:49 GMT
Content-Length: 5434

更新2:
如果我参加 existingResponse =替换了,我可以在服务器上打开错误/ NOTFOUND。但仍然有空白页要播/ MyProject的/富/条

Update 2: If I take existingResponse="Replace" away, I can open Error/NotFound on the server. But still got blank page on MyServer/MyProject/foo/bar

推荐答案

在我的情况的原因是在IIS中 - 网络设置 - 请求过滤 - SQL注入过滤器...

In my case the reason was in IIS - web settings - Request Filtering - SQL injection filter...

如果URL或查询字符串包含; ,响应与状态404.19结束 - 被过滤规则拒绝。则显示空白页。 IIS重定向到自定义错误这样 http://server.com/ Error404.aspx 404; HTTP:?//server.com/missingURL 和焦; 就是为什么请求筛选结束你的,因为SQL注入的要求

If url or query string contains ;, response ends with status 404.19 - Denied by filtering rule. Then blank page is displayed. IIS redirect to custom error like this http://server.com/Error404.aspx?404;http://server.com/missingURL and the char ; is why Request Filter end your request because of SQL injection.

这篇关于部署到IIS 7.5后的空白自定义404页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆