我有什麼?FBA雙重認證問題
我在其中一個web應用程序中配置了FBA,使用開箱即用的登錄頁面,並在下拉框中選擇Windows或FBA登錄。一切工作正常。
我想要什麼?
我想要一個自定義登錄頁面,其中包含用戶名和密碼文本框以及用於驗證Windows和FBA用戶身份的登錄按鈕。爲了區分兩個不同的登錄名,我想處理OnAuthenticate事件並檢查用戶名是否包含'\',那麼假設它是Windows用戶,否則它是FBA用戶。
這是代碼寫在OnAuthenticate事件處理程序:
protected void signinControl_Authenticate(object sender, AuthenticateEventArgs e)
{
string fullUserName = signinControl.UserName;
string username = null;
if (fullUserName.Contains("\\")) //Windows user
{
string domain = fullUserName.Substring(0, fullUserName.IndexOf("\\"));
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domain))
{
username = fullUserName.Substring(fullUserName.IndexOf("\\") + 1);
e.Authenticated = pc.ValidateCredentials(username, signinControl.Password);
}
}
else //FBA user
{
e.Authenticated = Membership.ValidateUser(fullUserName, signinControl.Password);
}
}
我會面臨什麼問題?
上述代碼適用於FBA用戶。但是,當我嘗試使用Windows用戶登錄時,即使e.Authenticated
在驗證後設置爲true
,它也會拋出此錯誤:「您的登錄嘗試失敗,請重試。」
e.Authenticated = pc.ValidateCredentials(username, signinControl.Password);
我相信,設置e.Authenticated
到true
應該從登錄頁面將用戶重定向到所請求的頁面。如果我必須做其他事情才能讓Windows用戶登錄,是否有人可以幫助我?
更新-1:
我用SetAuthCookie()
方法來設置Cookie的明確,還是一樣的結果。
FormsAuthentication.SetAuthCookie(username, true);
我用一個Web部件來創建我的自定義登錄表單並使用此解決方案:http://jcapka.blogspot.com/2010/12/nicer-cla IMS爲登錄頁的SharePoint 2010.html – toma19