bare bones MembershipProvider in sitecore

后端 未结 1 1953
遇见更好的自我
遇见更好的自我 2021-01-14 15:45

I\'m trying to implement a really really simple MembershipProvider for sitecore, but i\'m not sure if it\'s too simple to actually work. Basically we already have a

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-14 16:06

    Implementing a membershipprovider is a lot of work for what you seem to need. If I were you I would implement a scenario, where you create a virtual user everytime someone needs to be logged in. So the logic would be to check if a user has your token, then create a virtual user, log the virtual user in and you should be good to go.

    Here is a guide on the virual user thingie: http://sdn.sitecore.net/Articles/Security/Faking%20user%20roles/Virtual%20user.aspx

    EDIT: The code in the link is depricated. Here is how you add virtual users:

       userName = "extranet\\"+userName    
       User userItem = AuthenticationManager.BuildVirtualUser(userName, true);   
       userItem.Profile.Initialize(userName, true);    
       userItem.Profile.Email = userName + "@yourdomain.com";   
       userItem.Profile.Save();
    
       AuthenticationManager.Login(userItem.Name)
    

    EDIT 2: I have the following code:

        public class TestVirtualUserProcessor : HttpRequestProcessor
        {
    
    
          public override void Process(HttpRequestArgs args)
          {
            HttpContext.Current.Response.Write(Sitecore.Context.User.Name + "
    "); HttpContext.Current.Response.Write(Sitecore.Context.User.IsAuthenticated + "
    "); CreateVirtualUser("jenneren"); HttpContext.Current.Response.Write(Sitecore.Context.User.Name + "
    "); HttpContext.Current.Response.Write(Sitecore.Context.User.IsAuthenticated + "
    "); } private static void CreateVirtualUser(string name) { string userName = "extranet\\" + name; User userItem = AuthenticationManager.BuildVirtualUser(userName, true); userItem.Profile.Initialize(userName, true); userItem.Profile.Save(); AuthenticationManager.Login(userItem.Name); } }

    This outputs the following the first time I hit the frontend:

    extranet\Anonymous False extranet\jenneren True

    And the second time I hit the frontend I get:

    extranet\jenneren True extranet\jenneren True

    So it should work. Cheers Jens

    0 讨论(0)
提交回复
热议问题