16 Şubat 2012 Perşembe

Sharepoint Infopath getting logged in username in Forms Authentication

If you use Claims Based Auth., you cannot get a proper username with the command ın Infopath:


this.Application.User.LoginName

You ll get something like :
i:0#.|PROVIDERNAME|Username

You can replace the string but it 's not a proper way to do it.

You can use 2 methods:

1.  SPUser user = SPContext.Current.Web.CurrentUser;
user.userName would get you the proper name

or

2.

string userName = null;
SPClaimProviderManager mgr = SPClaimProviderManager.Local;
if (mgr != null)
{
       userName = mgr.DecodeClaim(SPContext.Current.Web.CurrentUser.LoginName).Value;
}

Hiç yorum yok:

Yorum Gönder