2017-01-15 15 views
0

ASP.NET MVC에서 401에 대해 내 web.config 오류 페이지를 표시하려고하는데 404 오류 페이지 만 작동합니다. 인증 프로세스는 .net ID 프레임 워크가 아닌 내 자신의 것입니다.Windows 인증이없는 MVC의 사용자 정의 401 오류 페이지

내 컨트롤러 동작 방법에 새로운 401 예외가 표시됩니다.

작업 :

[HttpGet] 
[HandleError] 
public ActionResult Delete(int id) 
{ 
    //if (user.IsInRole(RoleType.DELETE)) 
    if (myOwnUserClass.IsInRole(RoleType.DELETE)) 
    { 
     return View(); 
    } 
    else 
    { 
     return new HttpStatusCodeResult(401); 
     //return PartialView("_unauthorize"); 
    } 
} 

의 Web.config

<customErrors mode="On" defaultRedirect="~/Error/Index"> 
     <error statusCode="401" redirect="~/Error/Unauthorized" /> 
     <error statusCode="404" redirect="~/Error/NotFound"/> 
    </customErrors> 

내가 401 에러 페이지, 내 자신의 NOT 기본 얻는다.

Default 401 error page similar to this

나는이에 대한 스택 오버플로를 검색하지만, 그 대답은 나를 위해 일하지 않았다.

답변

1

customErrors을 비활성화하고 대신 httpErrors을 사용하여 이러한 오류를 처리 할 수 ​​있습니다.

<system.web> 

    <customErrors mode="Off" /> 

    <!-- other tags removed for brevity --> 
</system.web> 
<system.webServer> 

    <httpErrors errorMode="Custom" existingResponse="Auto"> 
    <clear /> 
    <error statusCode="401" responseMode="ExecuteURL" path="/Error/Unauthorized" /> 
    <error statusCode="404" responseMode="ExecuteURL" path="/Error/NotFound" /> 
    <error statusCode="500" responseMode="ExecuteURL" path="/Error" /> 
    </httpErrors> 

    <!-- other tags removed for brevity --> 
</system.webServer> 
+0

흠 나는 httpErrors로 확인하게하고 다시 연락 할 것입니다. –