【发布时间】:2021-03-01 05:09:54
【问题描述】:
我有一个本地运行的 MVC 项目,我为它设置了 CI/CD 管道。我遇到的问题是,当我打开服务器时,它总是将我重定向到错误页面。这是我看到的结果:
并且 URL 总是添加一个aspxerrorpath 参数:
我有自定义错误页面,下面是我的 web.config 文件的内容:
<customErrors mode="On">
<error statusCode="404" redirect="~/Error/NotFoundError"/>
<error statusCode="500" redirect="~/Error/InternalServerError"/>
</customErrors>
这是我的错误控制器:
public ActionResult NotFoundError()
{
return View("~/Views/Shared/CustomErrors/_Error404.cshtml");
}
public ActionResult InternalServerError()
{
return View("~/Views/Shared/CustomErrors/_Error500.cshtml");
}
现在,这在本地运行良好;但是,它在 Azure 环境中中断。即使我手动更改网址,它也会在我导航到的所有页面上出现错误。这些页面显示在网络选项卡中,302,但我仍然收到此错误。我尝试了以下方法来修复它,但仍然得到相同的结果:
public ActionResult NotFoundError(string aspxerrorpath)
{
if (!string.IsNullOrWhiteSpace(aspxerrorpath))
return RedirectToAction("~/Views/Shared/CustomErrors/_Error404.cshtml");
return View("~/Views/Shared/CustomErrors/_Error404.cshtml");
}
public ActionResult InternalServerError(string aspxerrorpath)
{
if (!string.IsNullOrWhiteSpace(aspxerrorpath))
return RedirectToAction("~/Views/Shared/CustomErrors/_Error404.cshtml");
return View("~/Views/Shared/CustomErrors/_Error500.cshtml");
}
有人能解释一下发生了什么吗?我该如何解决这个错误?
【问题讨论】:
-
如果您需要进一步的帮助,请告诉我。
标签: c# asp.net-mvc azure azure-pipelines