SharePoint Blogs / SharePoint University
SharePoint Blogs and SharePoint University - all in one place!
Need SharePoint Training? Attend a SharePoint Bootcamp!

Please delete cookies related to sharepointblogs.com and sharepointu.com to resolve login issues!

Programmatically adding a SiteCollection with custom membership provider

SPWebApplication.Sites.Add should be an easy function to call. Among the parameters is ownerLogin. This works a charm when your web application is configured for the default windows authentication. But in my case it was a custom membership provider. I tried several times to do it while specifying membershipprovider:ownername. BUT it continuously gives "User cannot be found".

At the end i had to resort to the Admin.asmx web service. It provides us a CreateSite function with almost the same functionlity as the SPWebApplication.Sites.Add(). The only catch here is that this method will only work on the central admin web application. You cannot use it on any content applications. ( REF: WSS SDK Admin::CreateSite )

So here is how i ended up solving my problem

//Create an instance of the Central Admin web service
_Admin.Admin _adm = new _Admin.Admin();
           
 //Get the url for the Admin site.
string caURL = System.Configuration.ConfigurationSettings.AppSettings["centralAdminApplicationURL"].ToString();
           
//set the URL to the "REQUIRED" central admin site
_adm.Url = caURL + "/_vti_adm/admin.asmx";

//Prefix the membership provider name to the ownerlogin.
string provider = System.Configuration.ConfigurationSettings.AppSettings["membershipProviderKey"].ToString();
ownerLogin = provider + ":" + ownerLogin;
           
//set the credentials for current web service call.
_a.Credentials = new System.Net.NetworkCredential("user", "password", "DOMAIN");
_a.CreateSite(siteCollURL, title, description, langID, template, ownerLogin, ownerName, ownerEmail, "", "");            


Posted 01-15-2008 5:46 PM by helloibm

Comments

Links (1/15/2008) « Steve Pietrek’s SharePoint Stuff wrote Links (1/15/2008) « Steve Pietrek’s SharePoint Stuff
on 01-15-2008 8:40 PM

Pingback from  Links (1/15/2008) « Steve Pietrek’s SharePoint Stuff

Ariel wrote re: Programmatically adding a SiteCollection with custom membership provider
on 09-02-2008 12:32 PM

that user cannot be found msg may be coming because you were not specifying a prefix needed for custom membership providers, like

Passport:pepino@hotmail.com

Harry Solsem wrote re: Programmatically adding a SiteCollection with custom membership provider
on 12-10-2008 1:27 AM

Did anyone figure this one out? I'd really like to do this without using the  Admin.asmx web service.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Need SharePoint Training? Attend a SharePoint Bootcamp!
Posts (c) their respective authors. Everything else (c) 2009 SharePoint Experts, Inc.