2017-03-13 2 views
0

내 응용 프로그램에 대한 사용자 정의 오류 페이지를 만들려고하는데 대부분의 경우 작동하지만 403 오류는 아닙니다.ASP MVC 5 - 403 customError가 작동하지 않습니다.

내의 Web.config :

<customErrors mode="On" defaultRedirect="~/Error"> 
    <error statusCode="404" redirect="~/Error/NotFound" /> 
    <error statusCode="500" redirect="~Error/InternalServer" /> 
    <error statusCode="403" redirect="~Error/Forbidden" /> 
</customErrors> 

나는 이러한 요청을 위임하는 ErrorController 있습니다. 404 오류가 발생하면 사용자 정의 오류 페이지가 표시되지만 403은 표시되지 않습니다. 기본 IIS 403 - Forbidden 페이지를 받고 있는데도 사용자 정의 오류 페이지를 설정했습니다. 나는 주변을 둘러보고 <httpErrors> 대신에 빈 페이지를 매번 제공하는 것처럼 보였습니다.

여기 내 Global.asax가 도움이 있다면 :

void Application_Error(object sender, EventArgs e) 
{ 
    Exception exc = Server.GetLastError(); 

    if (exc is HttpUnhandledException) 
    { 
     // Pass the error on to the error page. 
     Server.Transfer("ErrorPage.aspx?handler=Application_Error%20-%20Global.asax", true); 
    } 
} 

답변

2

U는 IIS 7 +에 대한 새로운 접근 방식을 사용할 수 있습니다.

<httpErrors errorMode="Custom" existingResponse="Replace"> 
     <remove statusCode="403" /> 
     <remove statusCode="404" /> 
     <remove statusCode="500" /> 
     <error statusCode="403" path="/Error" responseMode="ExecuteURL" /> 
     <error statusCode="404" path="/Error/404" responseMode="ExecuteURL" /> 
     <error statusCode="500" path="/Error/500" responseMode="ExecuteURL" /> 
</httpErrors> 

system.webServer 섹션의 httpErros 섹션.

IIS 구성 refence : https://www.iis.net/configreference/system.webserver/httperrors
또한 관련 질문 : What is the difference between customErrors and httpErrors?

관련 문제