Login

Redirect to your own MySite Landing Page


Have you ever wanted to redirect a user to your own MySite landing page.  It is very easy to do with a single delegate control.  This will allow your SharePoint sites to have a profile page such as MyDevCow at any location in the site.  This code would run when you click the persons profile and click My Settings

mysettings

First create a user control with nothing on the page.  Something like the following

<%@ Control Language="C#" Inherits="DevCow.SharePoint.Controls.DevCowUserProfileRedirect,DevCow.SharePoint,Version=1.0.0.0,Culture=neutral,PublicKeyToken= 0528d6137835b00a" %>

Now create the code behind for a user control that receives a userprofile from the user information list.

public class DevCowUserProfileRedirect : UserControl, IFormDelegateControlSource
{
    #region IFormDelegateControlSource Members

    public void OnFormInit(object objOfInterest)
    {
        SPListItem user = objOfInterest as SPListItem;
        if (user != null)
        {
            this.RedirectIfNecessary(user);
        }

    }

    private void RedirectIfNecessary(SPListItem user)
    {
        //Redirect to hard coded site
        SPUtility.Redirect("http://sharepoint.devcow.com/Pages/DevCowProfile.aspx", SPRedirectFlags.Default, this.Context);
    }

    public void OnFormSave(object objOfInterest)
    {
    }

    #endregion
}

Finally create a Feature with an elements manifest that has the delegate control lower than 100.  Make sure to use the ID of ProfileRedirection

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Control Id="ProfileRedirection" Sequence="50" ControlSrc="~/_controltemplates/DevCow/DevCowMySiteRedirection.ascx"/>
</Elements>

Digg It!  StumbleUpon  Reddit  Del.icio.us  NewsVine  Furl  BlinkList  Ma.gnolia  Technorati

» Trackback URL to this Post

http://sharepointguys.com/brendon/trackback.ashx?id=20

Comments

#1 Bastiaan Kortenbout on 12.18.2008 at 8:24 AM

In my case it was not necessary to inherit from IFormDelegateControlSource (looking at the DevCowUserProfileRedirect class). The onFormInit method didn't hit my breakpoint in my solution, so nothing was redirected to my custom profileEdit page. I used the onLoad method instead. Worked like a charm :)

#2 Brendon Schwartz on 12.18.2008 at 8:38 AM

If onFormInit did not fire the event it usually means your class was not loaded correct into SharePoint. The reason you inherit from the interface IFormDelegateControlSource is because that is what they delegate control is replacing.

If you override the onLoad method then you are actually replacing the way the page works and this would not be a long term supportable and pluggable method for maintaining your site. The idea is that you can just deactivate the delegate control and the base functionality would work again. In fact in the real implementation I did the function checked to see if the redirect page was valid and if not allowed the system to go to the default page for loading.

Hope that helps.

» Trackbacks & Pingbacks

  1. Pingback from Links (6/17/2008) « Steve Pietrek - Everything SharePoint