简体   繁体   English

asp.net mvc5中服务器上的自定义错误

[英]custom errors on the server in asp.net mvc5

I have got a problem with my application in asp.net mvc 5. I try to create custom error views. 我在asp.net mvc 5中的应用程序遇到问题。我尝试创建自定义错误视图。 I create it by sites: first site , second site 我是通过以下站点创建的: 第一个站点第二个站点

when application is running like local site, everything works fine, but when i deploy it on the server, custom error pages dont work. 当应用程序像本地站点一样运行时,一切正常,但是当我在服务器上部署它时,自定义错误页面不起作用。

In web config my code looks like: 在Web配置中,我的代码如下所示:

<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/ErrorPages/Error500.cshtml" >
  <error statusCode="500" redirect="~/ErrorPages/Error500.cshtml"/>
  <error statusCode="404" redirect="~/ErrorPages/Error404.cshtml"/>
</customErrors>

... ...

<httpErrors errorMode="Custom" existingResponse="Replace">
  <remove statusCode="500"/>
  <error statusCode="500" path="/ErrorPages/Error/Error500" responseMode="ExecuteURL"/>
  <remove statusCode="404"/>
  <error statusCode="404" path="/ErrorPages/Error/Error404" responseMode="ExecuteURL"/>
</httpErrors>

Error Controller: 错误控制器:

public ActionResult Error500()
    {
        Response.StatusCode = 500;

        return View();
    }

    public ActionResult Error404()
    {
        Response.StatusCode = 404;

        return View();
    }

and view: 并查看:

@{
    ViewBag.Title = "Error404";
}

Someone knows what is wrong? 有人知道怎么了吗?

I'm quite sure the reason it's not working when you're deploying is because you're running different IIS versions. 我非常确定在部署时它不起作用的原因是因为您运行的是不同的IIS版本。

Have a look at Marco's answer in this thread. 看看Marco在此主题中的答案。 I can't explain it better: ASP.NET MVC 404 Error Handling 我无法更好地解释它: ASP.NET MVC 404错误处理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM