1

フォーム ベース認証 (FBA) を使用している WSS 3.0 サイトがあります。ログイン画面を取得するのではなく、特定のユーザーが自動的にログインできるようにサイトを設定したいのですが、これを行う最善の方法がわかりません。

実際、この記事に基づいて、ログインを処理する HTTP モジュールを作成済みです。より具体的には、別のログイン ページを作成し、そのページにアクセスすると目的のユーザーとしてログインします。しかし、ブラウザを閉じた後もユーザーはログインしたままになります。つまり、ブラウザを起動し、別のログイン ページに移動すると、HTTP モジュール コードがトリガーされ、目的のユーザーとしてログインし、ブラウザを閉じます。その後、サイトにアクセスしようとすると、以前のユーザーとしてサイトにログインしているため、サイトの標準のログイン ページがスキップされます。

私の質問は、どうすれば確実にログオフできるかということになると思います。HTTP モジュール/ハンドラーでこれを行う方法はありますか、または global.asax で何かしたいですか?

4

1 に答える 1

0

愚かな私。FormsAuthentication.RedirectFromLoginPage コマンドの Cookie パラメータを True に設定しました。つまり、認証 Cookie は 50 年間保持されます。私が望んでいたのは、ブラウザーが閉じられたときに Cookie が消えるようにすることでした。cookie パラメータが False に設定されている場合、これは簡単に実行できます。誰かが興味を持っているなら、これが私のコードです...

Imports System.Web
Imports System.Web.Security
Imports System.Collections.Specialized
Imports System.Security.Principal
Imports System.Threading
Imports System.Web.UI

Public Class AuthModule
    Implements IHttpModule

    Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
    End Sub

    Public Sub Init(ByVal app As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
        AddHandler app.PreRequestHandlerExecute, New EventHandler(AddressOf OnPreRequestHandlerExecute)
    End Sub

    Public Sub OnPreRequestHandlerExecute(ByVal sender As Object, _
                                            ByVal e As EventArgs)

        ' Check to see if the alternate page has been accessed
        If HttpContext.Current.Request.Url.ToString.ToUpper.EndsWith("AUTOLOGIN.ASPX") Then
            ' Alternate page has been accessed, so log in using predetermined account

            ' Retrieve the user name and password
            Dim userName As String = "user"
            Dim userPassword As String = "password"

            ' Build the user id
            Dim roles As String() = Nothing
            Dim webIdentity As New GenericIdentity(userName, "Form")
            Dim principal As New GenericPrincipal(webIdentity, roles)

            ' Specify the user
            HttpContext.Current.User = principal
            Thread.CurrentPrincipal = principal

            ' Redirect from the login page to the start page
' Note, this is the line I initially had incorrect.  That is, I had the
' second parameter set to True, which will persist the authentication cookie.
' Setting the second parameter to False will cause the authentication cookie
' to go away when the browser is closed.  Yeah!
            FormsAuthentication.RedirectFromLoginPage(HttpContext.Current.User.Identity.Name.ToString, False)
        End If

    End Sub

End Class
于 2009-06-26T18:52:07.450 に答える