【问题标题】:sitecore user domain and roles returning nullsitecore 用户域和角色返回 null
【发布时间】:2013-07-31 12:25:26
【问题描述】:

我有一个带有前端登录页面的站点核心设置,供外网用户访问站点内的受限页面。

Extranet 用户当前正在登录,且持久性标志相等

global::Sitecore.Security.Domains.Domain domain = global::Sitecore.Context.Domain;
var isLogginedIn = AuthenticationManager.Login(domain + @"\" + email, password, true);

这工作成功并且上下文设置正确。

以下是在同一请求中登录后立即窗口的输出。

global::Sitecore.Context.User.Domain
extranet

global::Sitecore.Context.User.Roles.Count()
1

global::Sitecore.Context.User.IsAuthenticated()
true

用户登录后,用户将被重定向到他们想要访问的页面。

以下是任何后续请求的即时窗口输出

global::Sitecore.Context.User.Domain
null

global::Sitecore.Context.User.Roles.Count()
0

global::Sitecore.Context.User.IsAuthenticated()
true

有人知道为什么我可能会在后续请求中丢失一些上下文项吗?

提前致谢

【问题讨论】:

    标签: login sitecore sitecore6


    【解决方案1】:

    您似乎正在尝试为 Sitecore 创建自己的登录页面。在这种情况下,您可以尝试启动logginging 管道而不是调用AuthenticationManager.Login 方法:

    var loggingInArgs = new LoggingInArgs
    {
        Username = userName,
        Password = password,
        StartUrl = startUrl
    };
    
    Pipeline.Start("loggingin", loggingInArgs);
    bool isLogginedIn = loggingInArgs.Success;
    

    【讨论】:

    • 感谢您的快速响应,但我无法使用该方法登录。我收到以下消息:You do not have access to the system. If you think this is wrong, please contact the system administrator.\n\nYour login attempt was not successful. Please try again.\n\nYou do not have access to the system. If you think this is wrong, please contact the system administrator.\n\n 据我了解,登录管道仅用于后端访问。这是外网域网站用户的登录页面。
    【解决方案2】:

    这更像是一个隐藏此问题的补丁,而不是一个适当的解决方案,但我会发布任何人以防万一它触发其他人对此有任何进一步的想法。

    我在自定义管道期间调用以下代码

    if (user.Domain == null && user.IsAuthenticated)
    {
       var domainUser = string.Format(@"extranet\{0}", user.LocalName);
       var membershipUser = Membership.GetUser(domainUser);
    
       if (membershipUser != null)
       {
          AuthenticationManager.Login(domainUser, membershipUser.GetPassword(), true);
       }
    }
    

    调用后,用户已正确设置域和角色。奇怪的是,此后的所有其他请求都有一个正确设置的用户。

    【讨论】:

      【解决方案3】:

      我遇到过域为空且角色为空的确切问题。 原因是我使用了 asp:Login 控件来登录用户。当我用标准的 Text、Password 和 Button 控件替换它时,问题就消失了。

      【讨论】:

        猜你喜欢
        • 2017-04-05
        • 1970-01-01
        • 2011-07-25
        • 1970-01-01
        • 1970-01-01
        • 2013-07-08
        • 1970-01-01
        • 2013-05-10
        • 1970-01-01
        相关资源
        最近更新 更多