簡體   English   中英

自動登錄和退出FBA SharePoint網站

[英]Automatically logging into and out of FBA SharePoint site

我們有一個WSS 3.0站點,該站點正在使用基於表單的身份驗證(FBA)。 我們想要設置站點,以便某些用戶可以自動登錄,而不是登錄屏幕,但我不確定執行此操作的最佳方法。

實際上,根據本文 ,我已經創建了一個用於處理登錄的HTTP模塊。更具體地說,我創建了一個備用登錄頁面,當單擊該頁面時,它將以所需用戶身份登錄。 但是,在我關閉瀏覽器后,它可以使用戶保持登錄狀態。 也就是說,我啟動瀏覽器,轉到備用登錄頁面,我的HTTP模塊代碼被觸發並以所需用戶身份登錄,然后關閉瀏覽器。 然后,當我嘗試訪問該站點時,將跳過該站點的標准登錄頁面,因為我仍以較早的用戶身份登錄到該站點。

我想我的問題歸結為如何確保我注銷? 有沒有辦法使用HTTP模塊/處理程序來執行此操作,或者我想在global.asax中執行某些操作?

傻我 我將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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM