How can I login programatiacally 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 ?
How can I login programatiacally 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 ?
Not really. What you can do, however, is write a supporting web service for your desktop application, and have that run in a Sitecore context.
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.
Use a SecurityDisabler to make your webservice run in the context of an Admin user.
using (new Sitecore.SecurityModel.SecurityDisabler()) { // do stuff here }
For more specific control you can use a UserSwitcher.
From the Security API Cookbook page 34 (http://sdn.sitecore.net/Reference/Sitecore%206/Security%20API%20Cookbook.aspx)
string domainUser = @"domain\user";
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
}
}
There is an easier way to accomplish your goal:
Sitecore may tell you that what you are trying to do will not work. But trust me, this works and I've used this method in a project before.
Additional details: Sitecore uses the Master, Core and Web DBs as it's data store. My suggested method uses Sitecore APIs to write directly to the DBs. When using this method, you'll need to be aware of the cache implications.
cheers!