窗体身份验证将随着RETURNURL其他信息 [英] Forms Authentication adding additional information along with ReturnUrl

查看:201
本文介绍了窗体身份验证将随着RETURNURL其他信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用时,应用程序需要重定向到登录页面是有一个事件或任何扩展点,这将让我做更多的工作,以请求之前它重定向到登录页面?

With Forms Authentication when the app needs to redirect to sign-in page is there an event or any extensibility point that will let me do additional work to the request before it redirects to the sign-in page?

我想发送的查询字符串的其他信息可能会有所不同,例如,它不会工作,只是静态地嵌入在we​​b.config中的loginUrl节点的链接。

I would like to send additional information in the query string that could vary such that it wouldn't work to just statically embed that in the link in the loginUrl node in the web.config.

编辑:为了澄清,我想先截获请求重定向即可登录

For clarification, I want to intercept the request prior to being redirected TO the login page.

示例:

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

和之前用户被重定向到 HTTP://the/interwebs/login.aspx 我会希望能够在查询值收拾这样的URL可能最终会像 HTTP://的/ interwebs / login.aspx的?行动=刷新

And prior the user being redirected to http://the/interwebs/login.aspx I would like to be able to pack in query values so the url could end up something like http://the/interwebs/login.aspx?Action=Refresh

推荐答案

我以前用的HTTP模块做到了这一点。我的例子(精简),在vb.net。我只是检查401状态code和做我自己的重定向。这里的大招是,我不得不删除并重新添加在web.config的HttpModules,以确保我的HttpModule从URL授权模块的阶梯。就我而言,我有一些URL重写本地化,我需要发送的区域设置ID的登录页面,因为它失去了URL授权模块在正常的重定向。我大量使用反射的建立起来的基本路径(未显示),因为这些是私有方法。

I've done this before with an http module. My example (stripped down), in vb.net. I'm just checking for a 401 status code and doing my own redirect. The big trick here was that I had to remove and add back the web.config httpModules to make sure my httpmodule stepped in from of the url authorization module. In my case I had some url rewriting for localization, and I needed to send the locale ID to the login page as it was lost by the normal redirect in the url authorization module. I made heavy use of Reflector to build up the base path (not shown), as these are private methods.

    Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
        AddHandler context.EndRequest, AddressOf Context_EndRequest
    End Sub

    Private Sub Context_EndRequest(ByVal sender As Object, ByVal e As EventArgs)

        If TypeOf sender Is HttpApplication Then

            Dim hApplication As HttpApplication = DirectCast(sender, HttpApplication)
            Dim hContext As HttpContext = hApplication.Context

            If (hContext.Response.StatusCode = &H191) Then

                hContext.Response.Redirect(String.Format("{0}?ReturnUrl={1}&someparam2={2}", basepath, HttpUtility.UrlEncode(hContext.Request.RawUrl), someparam2))

            End If

        End If

    End Sub

web.config中的变化

  <httpModules>
      <clear/>
      <!-- custom -->
      <add name="SomeHttpModule" type="SomeCompany.SomeProduct.SomeHttpModule"/>
      <!-- add back defaults, exlude PassportAuthentication, AnonymousIdentification, Profile -->
      <add name="OutputCache" type="System.Web.Caching.OutputCacheModule"/>
      <add name="Session" type="System.Web.SessionState.SessionStateModule"/>
      <add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule"/>
      <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule"/>
      <add name="RoleManager" type="System.Web.Security.RoleManagerModule"/>
      <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule"/>
      <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule"/>
  </httpModules>

这篇关于窗体身份验证将随着RETURNURL其他信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆