MySite How to find account name of users profile that is currently being displayed

Answered MySite How to find account name of users profile that is currently being displayed

  • Sunday, July 29, 2012 4:09 PM
     
      Has Code

    I am working on a webpart that will sit on the profile page of mysite.

    This web part needs the accountname of the user being looked at.

    The displayed url is mysite/person.aspx.  To my understanding the actual url is

    mysite/person.aspx?accountname=DOMAIN\Username

    It appears when you look at another profile it is in this format.

    Currently to solve this the only thing I can think of something like this.

    string url;
    string urlformat = "{0}/person.aspx?accountname={1}";
    if(Request.QueryString["accountname"]==null)
    {
        url=string.format(urlformat,SPContext.Current.Web.Url,SPContext.Current.Web.CurrentUser.LoginName);
    }
    else
    {
        url = string.format(urlformat, SPContext.Current.Web.Url, Request.QueryString["accountname"];
    }
    

    Is there a better way to get this same data or should I just stick with the above?

All Replies