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 upgraded our test environment from SharePoint 2010 to 2013. We were using classic authentication in 2010, migrated to claims (NTLM) in 2013. The databases have been upgraded and attached but the sites are still in "2010 mode".

We have a .NET server control with a string "UserName" property on the masterpage. Before the upgrade, we passed the string "DEFAULT" as the UserName to the control and the current user's username was somehow picked up and passed along. After the upgrade, the literal string "DEFAULT" is being passed through instead.

I'm assuming this has something to do with using claims authentication now... is there a different keyword I can use to get the current username?

Note: I am aware I can work around this by re-creating the control with javascript/ajax. I want to know if it's possible to continue using the server control.

share|improve this question

1 Answer 1

I made a few helper methods to get the AD login name from the windows claims. Hopefully these will help you fix your .NET server control.

The full story is located here: http://steve.thelineberrys.com/getting-active-directory-userid-from-windows-claim-in-sharepoint-2013/

But below are the highlights:

//Regex needs more testing
//http://social.technet.microsoft.com/wiki/contents/articles/13921.sharepoint-2013-and-sharepoint-2010-claims-encoding.aspx
public const string CLAIMS_REGEX = @"(?<IdentityClaim>[ic])?:?0(?<ClaimType>[#\.5\!\+\-%?\\])(?<ClaimValueType>[\.\+])(?<AuthMode>[wstmrfc])(\|(?<OriginalIssuer>[^\|]*))?(\|(?<ClaimValue>.*))";

public static string GetAdUserIdForClaim(string login)
{
    string userName = login;

    foreach (Match m in Regex.Matches(login, CLAIMS_REGEX))
    {
        userName = m.Groups["ClaimValue"].Captures[0].Value;
    }
    return userName;
}
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.