Question

I have a strange problem for creating my sites programmatically. As a lot of people I know the method CreatePersonalSite of the UserProfile class. My scenario is when a user is clicking on some button it will automatically create his my site by code.

The problem is that it seems to be impossible. Indeed the CreatePersonalSite seems to be dedicated to administration application which has access to MySite content database as dbowner. When I try to do it with the context of the current user who is clicking on the button, I have an access denied from sql server telling me that the service account connecting to the mysite content DB cannot access. Which is normal since the mysite web application is running with another application pool account than the site where the user clicks the button.

So my question is how can I do to create the personal site connected as a normal user on a different web application than the mysite one? I thought about creating a web request to the mysitehost site collection + "/_layouts/mysite.aspx" but this very dirty. Else I can give dbowner access to the my site content db to the application pool account of the web application where the user is clicking the button... but is it safe and can it be done without issues?

Thank you.

Was it helpful?

Solution

So you want it to be user initiated, but not as part of the default process that is in place by visiting the /_layouts/mysite.aspx page?

I would likely use the button to redict them to the provisioning page which will of course include checks to make sure that the site does not already exist. If not, and you truly want to do something custom, you can use the runwithelevatedprivileges option which will run it as the account used for the application pool. http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx

Generally in cases where I have had to provision sites programatically they are being done in bulk, and by an administrative user. I would likely use PowerShell in this case.

OTHER TIPS

Can you check and confirm whether other users can browse to "About Me" page of the mysite created by the console application programatically.

Also note that in this scenario, the user's mysite which has been created programtaically, that particular user have not visited his/her mysite by creation.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top