我的 Web.Release.config 中有一个相对未受影响的 MVC4 项目,其中包含以下内容:
<system.web>
<customErrors mode="On" defaultRedirect="~/Error">
<error redirect="~/Error/NotFound" statusCode="404" />
</customErrors>
</system.web>
但它不起作用 - 在发布模式下我得到正常的错误页面。
如果我将该代码放在我的 Web.Config 中,它会按预期工作。我只希望在发布时应用它。
我也在 web.release.config 中试过这个:
<system.web>
<customErrors mode="On" defaultRedirect="~/Error" xdt:Transform="Replace">
<error redirect="~/Error/NotFound" statusCode="404" />
</customErrors>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
无济于事。
为什么会发生这种情况?
更新:如果我在 global.asax 中使用以下内容:
void Application_Error(object sender, EventArgs e)
{
#if DEBUG
#else
Response.Redirect("/Error");
#endif
return;
}
我得到了想要的行为。我觉得我应该只能使用 web.config 设置......所以我想保持打开状态。