Azure网站 - 404重定向到自定义404错误页面不起作用

时间:2015-02-17 02:03:07

标签: azure asp.net-mvc-5 azure-web-sites

在Azure网站中部署时,我的404重定向到NotFound(控制器操作)无法正常工作。我正在使用普通的浏览器404而不是我的自定义404页面。但是在Visual Studio中的localhost中进行调试时,它们可以在本地工作。这是我的Web.Config -

<system.web>
........
<customErrors mode="RemoteOnly" defaultRedirect="~/Error/Index">
  <error redirect="~/Error/NotFound" statusCode="404" />
</customErrors>
</system.web>

我的ErrorController -

public class ErrorController : Controller
{
    public ViewResult Index()
    {
        ViewBag.Title = "Error Page";
        var model = new ErrorViewModel() {ErrorMessage = "Sorry for the error!", TitleBar = "Error Page"};
        return View("Error", model);
    }

    public ViewResult NotFound()
    {
        Response.StatusCode = 404; //you may want to set this to 200
        return View("PageNotFound");
    }
}

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

似乎通过在web.config文件中添加以下内容来解决问题:

<system.webServer>
<httpErrors existingResponse="PassThrough" />
</system.webServer>

这是因为&#34; PassThrough&#34;留下现有的响应,只要有一个。因此,您可以定义错误页面。

相关问题