2009-06-26 14 views
1

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

実際にはthis articleに基づいて、ログインを処理するHTTPモジュールをすでに作成しています。具体的には、別のログインページを作成しました。そのページがヒットしたら、目的のユーザーとしてログインします。しかし、それはブラウザを閉じた後にユーザをログインさせたままにしています。つまり、ブラウザを起動して代替ログインページに行き、HTTPモジュールコードが起動され、目的のユーザーとしてログインした後、ブラウザを閉じます。サイトに移動しようとすると、以前のユーザーとしてサイトにログインしているため、サイトの標準ログインページはスキップされます。

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

+0

標準のログインページではなく、そのページをどのようにヒットするのですか? – Rob

+0

私たちは、ページのURLが代替ログインページであることを伝えることを計画しています。 「知っている」人は、ページにアクセスする他の方法があることを知っています。私は、SharePoint web.configを変更して、ログインページの代替ページを使用することもできると思います。 – LunaCrescens

答えて

0

愚かな私。 FormsAuthentication.RedirectFromLoginPageコマンドのcookieパラメータをTrueに設定しました。つまり、認証Cookieは50年間保存されます。私が望んだのは、ブラウザが閉じられたときにクッキーが消えてしまうことでした。これは、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 
関連する問題