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.


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.

  • Indeed I want that the my site is created in background when a normal user clicks on a particular button of the page. I don't want to use the standard _layouts/mysite.aspx page but a server side code like CreatePersonalSite method. For the case of running the code with runwithelevatedprivileges it will not work since this way of impersonation is using the application pool account of the current web application. In my case the mysite web application runs with another account. That's why the error is thrown in fact. – Win Jul 6 '12 at 7:44
  • Any help on this ? – Win Jul 6 '12 at 15:43
  • If you want this to work, then you would need to grant access to your other app pools to the MySite web app and content database. – Mike Oryszak Jul 6 '12 at 15:50
  • Yes, unfortunately this is what I did at the end... – Win Jul 26 '12 at 18:52

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.