【问题标题】:How to redirect role-based security exceptions to custom page (ASP.NET)如何将基于角色的安全异常重定向到自定义页面 (ASP.NET)
【发布时间】:2010-12-03 07:37:18
【问题描述】:

我有很简单的:

[PrincipalPermission(SecurityAction.Demand, Role = "Administrator")]
public partial class _Default : System.Web.UI.Page

这有效 - 如果角色不是管理员,它会拒绝访问。但是当它拒绝访问时,我只是得到一个白页(所有未处理的异常都在全局文件中提取并通过电子邮件发送/记录)。我如何告诉它在哪里失败?所以我可以显示一个安全异常页面。

【问题讨论】:

    标签: asp.net roles roleprovider


    【解决方案1】:

    在 Global.asax.cs 中,将以下内容添加到 Application_Error:

    if (exception.GetType() == typeof(System.Security.SecurityException))
                    Response.Redirect("SecurityExceptionPage.html");
    

    【讨论】:

    • 服务器端处理没问题!但是带有ajax调用的webmethod呢?他们不会引发 application_error...
    猜你喜欢
    • 2014-03-26
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-22
    相关资源
    最近更新 更多