- To get the logged in user name you have the following methods available in SharePoint 2010 Web Part User Control:
- this.Page.User.Identity.Name
- HttpContext.Current.User.Identity.Name
- SPContext.Current.Web.CurrentUser.LoginName
- SPContext.Current.Web.CurrentUser.Name
Programmatically converting login name to claim and vice versa
string
userName =
null
;
SPClaimProviderManager
mgr =
SPClaimProviderManager
.Local;
if
(mgr !=
null
)
{
userName = mgr.DecodeClaim(
SPContext
.Current.Web.CurrentUser.LoginName).Value;
}
Claims back and forth
string
userName =
null
;
SPClaimProviderManager
mgr =
SPClaimProviderManager
.Local;
if
(mgr !=
null
)
{
SPClaim
claim =
new
SPClaim
(
SPClaimTypes
.UserLogonName,
"myuser"
,
"http://www.w3.org/2001/XMLSchema#string"
,
SPOriginalIssuers
.Format(
SPOriginalIssuerType
.Forms,
"myprovider"
));
userName = mgr.EncodeClaim(claim);
}
No comments:
Post a Comment