2016-03-04 94 views
2

AuthenticationManager.Login desn't的工作,我想通過AuthenticationManager.Login(用戶)登錄用戶,但是當我檢查用戶通過AuthenticationManager.GetActiveUser(),我得到「外聯網\匿名「用戶。但是,當我嘗試登錄之前創建的虛擬用戶時,它可以正常工作。與指定用戶

我的代碼:

Log.Info(string.Format("Trying to login with unique key '{0}'...", uniqueKey), item); 
User user = FindDocCheckUserByUniqueKey(uniqueKey); 
Log.Info(string.Format("User found by unique key '{0}': {1}", uniqueKey, user != null ? user.Name : "null"), item); 
AuthenticationManager.Login((user != null ? user : BuildDocCheckUser()).Name); // login user found by unique key or the virtual user 
user = AuthenticationManager.GetActiveUser(); 
Log.Info(string.Format("Active user: {0}", user != null ? user.Name : "null"), item); 
Log.Info(string.Format("Active user is authenticated: {0}", user != null && user.IsAuthenticated), item); 

日誌輸出爲真正的用戶(不工作):

3640 13:23:30 INFO Trying to login with unique key '596e2c332f6b0f34241039ec8ce9c18d'... 
3640 13:23:30 INFO User found by unique key '596e2c332f6b0f34241039ec8ce9c18d': extranet\dc_596e2c332f6b0f34241039ec8ce9c18d 
3640 13:23:30 INFO Active user: extranet\Anonymous 
3640 13:23:30 INFO Active user is authenticated: False 

虛擬用戶(工作)日誌輸出:

3560 13:22:48 INFO Trying to login with unique key '395f625038a3293fe1f10eff84529556'... 
3560 13:22:48 INFO User found by unique key '395f625038a3293fe1f10eff84529556': null 
3560 13:22:48 INFO Active user: extranet\DocCheck User 
3560 13:22:48 INFO Active user is authenticated: True 

有沒有辦法強制用戶登錄?

+0

你可以嘗試給這個方法添加第二個參數AuthenticationManager.Login(user,true);這是來自AuthenticationManager類的方法:public static bool Login(string userName,bool persistent) –

+0

這不會'工作。同樣的效果。 :-( – tngraessler

+0

你能檢查FindDocCheckUserByUniqueKey(uniqueKey)爲什麼用戶爲空嗎?什麼是用戶的唯一ID? –

回答

1

您需要添加第二個參數登錄方法

AuthenticationManager.Login(user, true); 

你也需要檢查的密碼,因爲當用戶輸入的密碼不序列化。

0

找到解決方案!導入的用戶默認是禁用的。啓用它們使登錄過程起作用。 - 謝謝@SitecoreClimber給我密碼提示,所以我仔細看了一下sitecore的用戶管理器。 :-)