Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 0 down vote accepted

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.

share|improve this answer
    
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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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