非常简单。
我在AuthorizationFilter中抛出了UnauthorizedAccessException。我希望UnauthorizedAccessException转到错误页面,而不是/ Account / Login页面
我怎样才能做出改变?
答案 0 :(得分:3)
尝试在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
}
}
答案 1 :(得分:1)
您可以使用多个异常处理程序
try
{
// code here
}
catch (UnauthorizedAccessException)
{
Response.Redirect(errorPageUrl, false);
}
catch (Exception)
{
Response.Redirect(loginPageUrl, false);
}