In The Mix

As a SharePoint architect I have the business behind me and the Developers and IT Pro on my shoulders.

Creating Custom MySites July 1, 2008

Filed under: SharePoint — fmuntean @ 4:24 pm

Recently I was asked to create custom MySites, so I start looking how the MySites get currently created in MOSS 2007.

By using SharePoint Designer 2007 I have easily found that the Mysite link is on the Master page as expected sitting inside of a <SharePoint:DelegateControl> with ControlID=”GlobalSiteLink1″.

This is great news: we can change the control by using features without directly changing the master page. If you want to read more about this special SharePoint control follow the link to “The SharePoint DelegateControl Uncovered” on Patrik’s Blog.

For now let’s continue explaining the current implementation done by Microsoft.

The current control is “~/_controltemplates/mysitelink.ascx” with a sequence of 100 and points on the My Site Web App to a system page named “/_layouts/MySite.aspx”.

The “~/_controltemplates/mysitelink.ascx” control  inherits the Microsoft.SharePoint.Portal.WebControls.MySiteLinkUserControl class inside the Microsoft.SharePoint.Portal.dll assembly.

The next step was to take the Reflector and look inside that class.

The “/_layouts/MySite.aspx” page is hard coded (bad bad practice) inside the SetControl() method.

The MySite.aspx system page inherits the Microsoft.SharePoint.Portal.WebControls.CreatePersonalPage class inside the Microsoft.SharePoint.Portal.dll assembly.

On the FormLoad() method there is code to look for the userProfile.PersonalSite that is the equivalent of userProfile[PropertyConstants.PersonalSpace] and if empty create a new site by calling userProfile.CreatePersonalSite() public method.

Moving forward I found that inside that method the site template is hard coded (bad bad practice) to SPSPERS#0.

Now armed with all this information we can decide how to create a custom one.

There are few approaches:

1) Just modify the SPSPERS#0 site template on the file system.

2) Modify the MySite.aspx to derive from another page that you created and on FormLoad() create the site from another template. Make sure that you create the site during the POST because it does not work if trying to create it during GET.

3) Create a new MySiteLink control with a sequence lower than 100  that will replace the default one for MySite and point to a different system page of your own. That page will create the personal site or redirect to one if another already exists.

The preferred approach would be 3) as it offers the maximum flexibility and has the minimal impact on the farm if Microsoft decides later on to change the mechanism. Plus this option offers the possibility to safely deploy the custom MySites as a solution that later on will not be affected by HotFixes or Service Packs.

Advertisements
 

4 Responses to “Creating Custom MySites”

  1. moab Says:

    Excellent info – thanks. I am going to try to build #3 this week.

  2. EFR Says:

    Hi,

    I’m currently trying to create a mysite programmatically. The problem is that all the code examples shown on the Internet are supposed to be put into a console application executed on the server. On my site I want to create automatically the mysite after an action of standard user on a SharePoint intranet site. My probelm is that when I call CreatePersonalSite method,here is the message I get: “Updates are currently disallowed on GET requests. To allow updates on a GET, set the ‘AllowUnsafeUpdates’ property on SPWeb”. I tried everything like runwith elevated privileges, allowunsafeupdates etc. But not working. It seems that some permissions on the SSP are required and I’m wondering how the CreatPersonalSpace class is doing such impersonation. I didn’t find anything with reflector that can help me. If you have the answer I would appreciate that.

    Thanks.

  3. fmuntean Says:

    The easiest way to create a MySite for the current logged in user is to redirect to the same page that SharePoint uses to create the MySite.

  4. EFR Says:

    Hum, you’re right but the problem is that I want, when a user clicks on link to be redirected to a particular page, before loading the page, the mysite to be created at the same time. I tried to use some HttpWebRequest to call _layouts/mysite.aspx, but the problem with this solution is that there is some credential issues and I’m always getting some 401 unauthorized exception. So it seems that there is no real solution to my problem except creating a link on destination page to say to user “Click on this link for creating your mysite” with the link redirecting to _layouts/mysite.aspx.

    Ok so thank you for your help !


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s