- January
- 15
- 2008
Programmatically adding a SiteCollection with custom membership provider
Posted by helloibm
No Comments »
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, "", "");