2011-12-28 74 views
1

我的大部分ASP.NET网站都可供匿名网络用户访问。不过,在允许访问之前,我需要验证几个页面。我通过在web.config控制这样的:在登录页面上添加自定义内容

<authorization> 
    <allow users="*"/> 
</authorization> 

目前我logon.aspx文件是通用的,但我真的想告诉包括他为什么被重定向到登录页面的用户指令。例如:

在您可以自愿执行任务之前,请先登录,系统才能识别您的身份。

OR

你已经尝试编辑的事件。该系统只允许管理员执行此操作。请登录,以便我们确认您是此活动的管理员。

登录页面上的说明取决于用户在表单认证重定向之前尝试的内容。

我的问题是,登录页面如何确定采取了哪些操作?有没有办法将自定义查询字符串传递到登录页面?我想我可以解码ReturnUrl并使用它来尝试确定要显示的指令。然而,这种方法只是觉得......脏。我不喜欢登录页面依赖于系统中其他页面的URL名称。

有什么建议吗?

回答

0

为什么不使用自定义例外来做到这一点。

public class ClassName: Exception 
    { 
     protected ClassName() : base() {} 
     public ClassName(String message) : base(message) { } 
    } 

然后你做

public class First: ClassName 
{ 
    public First() : base("message") {} 
} 

public class Second: ClassName 
{ 
    public Second() : base("message") { } 
} 

现在你只赶上型类名的例外,看到消息的值,并将其传递到ASP标签或文本框或根据需要做

+0

如何处理异常pro穿越HTTP重定向? – Aheho 2011-12-28 17:26:57

0

您也可以在global.asax的Application.EndRequest中捕获重定向。

void Application_EndRequest(object sender, EventArgs e) 
    { 
     if (!HttpContext.Current.Request.IsAuthenticated && HttpContext.Current.Response.StatusCode == 302 && HttpContext.Current.Response.RedirectLocation != null && HttpContext.Current.Response.RedirectLocation.ToLower().Contains("login.aspx")) 
     { 
      // do some switching or determining here, or have items preset in your HttpContext.Current.Items[] 
      HttpContext.Current.Response.RedirectLocation += "&Action=blah"; 

     } 
    }