문제

Pretty straightforward.
I'm throwing an UnauthorizedAccessException in an AuthorizationFilter. I want UnauthorizedAccessException to head to an Error page, NOT to the /Account/Login page.
How can I make that change?

도움이 되었습니까?

해결책

You can use multiple exception handlers

        try
        {
            // code here
        }
        catch (UnauthorizedAccessException)
        {
            Response.Redirect(errorPageUrl, false);
        }
        catch (Exception)
        {
            Response.Redirect(loginPageUrl, false);
        }

다른 팁

Try setting up something like this in global.asax.cs

protected void Application_Error(object sender, EventArgs e)
{
    // excpt is the exception thrown
    // The exception that really happened is retrieved through the GetBaseException() method
    // because the exception returned by the GetLastError() is a HttpException
    Exception excpt = Server.GetLastError().GetBaseException();

      if(excpt is UnauthorizedAccessException)
      { 
        // redirect here
      }

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top