我想通过 AuthenticationManager.Login(用户)登录用户,但是当我通过 AuthenticationManager.GetActiveUser()检查该用户时,我得到 “extranet \ Anonymous”用户。但是,当我尝试登录之前创建的虚拟用户时,它可以正常工作。
我的代码:
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 :(得分:1)
您需要为登录方法添加第二个参数
AuthenticationManager.Login(user, true);
此外,您还需要检查密码,因为导入用户时密码不会被序列化。
答案 1 :(得分:0)
找到解决方案!默认情况下禁用导入的用户。启用它们可使登录过程正常运行。 - 谢谢@SitecoreClimber给我密码提示,所以我仔细查看了sitecore用户管理器。 : - )