我配置我的配置文件在MVC自定義錯誤。因此,自定義錯誤配置:配置自定義錯誤給出「錯誤太多重定向」在mvc
<customErrors mode="On">
<error statusCode="401" redirect="~/Views/UnAuthorized/ErrorUnauthorised"/>
<error statusCode="404" redirect="~/Views/UnAuthorized/ErrorResourceNotFound"/>
</customErrors>
<authentication mode="Windows" />
<authorization>
<deny users="?"></deny>
<allow users="*"></allow>
</authorization>
和服務器
<httpErrors errorMode="Custom" >
<remove statusCode="401" />
<error statusCode="401" path="http://localhost:port/UnAuthorized/ErrorUnauthorised" responseMode="Redirect" />
<remove statusCode="404"/>
<error statusCode="404" path="http://localhost:port/UnAuthorized/ErrorResourceNotFound" responseMode="Redirect" />
</httpErrors>
我的錯誤頁面與其他配置文件不同的文件夾,允許未授權的用戶在:
<allow users="*"></allow>
我錯誤頁面控制器是:
public class UnAuthorizedController : Controller
{
// GET: UnAuthorized
public ActionResult ErrorUnauthorised()
{
return View("ErrorUnauthorised");
}
public ActionResult ErrorResourceNotFound()
{
return View("ErrorResourceNotFound");
}
}
當我嘗試啓動應用程序時,它從這個頁面開始〜/ Views/UnAuthorized/ErrorUnauthorised並顯示瀏覽器消息「Too many redirects」當我刪除httpErrors部分時,應用程序通常以Index頁面啓動,但出錯時不會顯示了自定義錯誤頁
編輯 我結束了結論,即應用程序顯示錯誤「過多的重定向」如果我有我的配置文件都401和404錯誤。如果我刪除401錯誤,應用程序工作正常
請檢查您是否創建了ErrorUnauthorised,ErrorResourceNotFound視圖。由於服務器在每個請求上提供了401,404個狀態碼,因此重定向過多。 –
是的,我有每個頁面的意見,當我刪除httpErrors部分時,停止出現「太多重定向」消息,所以我想這不是從視圖 – Gamaboy