c# - Forms Authentication 添加附加信息以及 ReturnUrl

标签 c# asp.net .net-4.0 forms-authentication

当应用需要重定向到登录页面时,使用 Forms Authentication 是否有事件或任何扩展点可以让我在重定向到登录页面之前对请求做额外的工作?

我想在查询字符串中发送额外的信息,这些信息可能会有所不同,因此仅将其静态嵌入到 web.config 中 loginUrl 节点的链接中是行不通的。

编辑:为了澄清,我想在被重定向到登录页面之前拦截请求。

示例:

<authentication mode="Forms">
      <forms loginUrl="http://the/interwebs/login.aspx" timeout="2880" 
                enableCrossAppRedirects="true" />
</authentication>

并且在用户被重定向到 http://the/interwebs/login.aspx 之前我希望能够打包查询值,以便 url 最终可以是 http://the/interwebs/login.aspx?Action=Refresh 之类的东西

最佳答案

您可以通过处理事件 HttpApplication.AuthenticateRequest 来做到这一点

    private void Application_AuthenticateRequest(Object source, EventArgs e)
    {

        HttpApplication application = (HttpApplication)source;
        HttpContext context = application.Context;

        string cookieName = FormsAuthentication.FormsCookieName;
        HttpCookie authCookie = context.Request.Cookies[cookieName];

        if (authCookie == null || string.IsNullOrEmpty(authCookie.Value))
        {
            //... do something
        }

仅供引用,我们目前通过 IHttpModule 实现来执行此操作。

关于c# - Forms Authentication 添加附加信息以及 ReturnUrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3919495/

相关文章:

c# - 按值传递接口(interface)成员

c# - 触发内容模板

C# SQL查询异常

c# - 错误 - 词法分析器规则 'xxxx' 中的操作必须是单个最外层 alt 的最后一个元素

c# - WPF MVVM自定义排序问题

c# - ASP.Net 实时流式传输 IP 摄像机视频和音频

c# - ASP.NET 5 MVC 6 : How to configure startup to send a html file when not on any mvc route

c# - 局域网唤醒 - Linux - .Net Core

c# - Asp.net 获取 JQuery session

.net - XmlReader 无法识别 EndElement