c# - System.Web.HttpContext.Current.User.Identity.Name not consistent -
in our project using system.web.httpcontext.current.user.identity.name userid domain. few pages say, login or home page or many of them returning username expected domainname
domainname\userid
when want trying upload file using usercontrol on 1 of pages, throws exception returning directly username
like harry,burlington instead of dom\hburlingt .
we using windows authentication mode in our web,config , sample code thats throwing exception
public static string getcurrusersloginidentity() { string name = ""; if (system.web.httpcontext.current != null) name = system.web.httpcontext.current.user.identity.name; else { windowsidentity id = windowsidentity.getcurrent(); if (id != null) name = id.name; } //if still don't have name wrong if (string.isnullorempty(name)) throw new system.security.authentication.invalidcredentialexception("coult not retrieve idsid information user."); return name;
user.identity
, windowsidentity.getcurrent()
2 different things:
user.identity on msdn returns system.security.principal
object.
windowsidentity.getcurrent on msdn returns system.security.principal.iprincipal
object.
so no surprise seeing 2 different names.
btw, name of method getcurrusersloginidentity
misleading, since returns user's name not identity object itself.
and also, exception message contains spelling error: coult not retrieve idsid information user.
Comments
Post a Comment