c# - 如何在 ASP.Net 中更改 UnauthorizedAccessException 重定向到的位置

标签 c# asp.net unauthorizedaccessexcepti

非常简单。
我在 AuthorizationFilter 中抛出 UnauthorizedAccessException。我希望 UnauthorizedAccessException 转到错误页面,而不是/Account/Login 页面。
我怎样才能做出改变?

最佳答案

尝试在 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
      }

}

关于c# - 如何在 ASP.Net 中更改 UnauthorizedAccessException 重定向到的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11809219/

相关文章:

c# - 如何使用 .NET 获取当前季节? (夏季、冬季等...)

c# - 排序字典和列表 <>() 在 VS 2010 中有错误

asp.net - System.DirectoryServices.AccountManagement.UserPrincipal - localhost 但不是 iis

c# - 从复选框列表中的顶部项目中从 SQL 数据库中选择的数据被复制到所有 Gridview 行

asp.net - 我可以在没有管理员用户的情况下使用 Microsoft.Web.Administration 中的 ServerManager 作为应用程序池标识吗

c# - 我如何访问 C :\Program Files\in c#

.net - UnauthorizedAccessException 与 SecurityException

C# datetime format无法比较

c# - 从代码发送电子邮件时出现“5.7.1 Client does not have permission”错误

c# - 将大型 ASP.NET VB.NET 项目转换为 C# - 增量?