Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

sitecore6 - How can I login programmatically into Sitecore?

How can I login programmatically into Sitecore? For example if you would like to connect a small part of the Sitecore API to a desktop application, you would need to login into sitecore first to access the databases etc.

Can this be done?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As Mark said, you will need to create a web service that your desktop app will talk to. If you need to deal with permissions in that service you have two options.

  1. Use a SecurityDisabler to make your webservice run in the context of an Admin user.

    using (new Sitecore.SecurityModel.SecurityDisabler())
    {
        // do stuff here
    }
    
  2. For more specific control you can use a UserSwitcher.

    From the Security API Cookbook page 34

    string domainUser = @"domainuser"; 
    
    if (Sitecore.Security.Accounts.User.Exists(domainUser)) 
    { 
        Sitecore.Security.Accounts.User user = 
        Sitecore.Security.Accounts.User.FromName(domainUser,false); 
    
        using (new Sitecore.Security.Accounts.UserSwitcher(user)) 
        { 
            //TODO: code to invoke as user 
        } 
    } 
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...