Hi Friends,
I used below code to get windows authentication but it returns empty string after deployed empty string. Yesterday we implimented https certificate after that application failed.
i tried to add impersonate set true and false in web.config but no luck.
string sCurrentUserName = string.Empty;
if (HttpContext.Current.User != null)
{
sCurrentUserName = HttpContext.Current.User.Identity.Name.ToString();
}
if (sCurrentUserName == string.Empty)
sCurrentUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
if (HttpContext.Current.User != null)
{
sCurrentUserName = HttpContext.Current.User.Identity.Name.ToString();
}
if (sCurrentUserName == string.Empty)
sCurrentUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
if (sCurrentUserName != null && sCurrentUserName.Trim().Length > 0)
{
string[] splittedName = sCurrentUserName.Split('\\');
if (splittedName.Length > 0)
{
string sDomain = splittedName[0].ToString();
return (splittedName.Length > 1) ? splittedName[1].ToString().Trim().ToUpper() : splittedName[0].ToString().Trim().ToUpper();
}
}
return string.Empty;
{
string[] splittedName = sCurrentUserName.Split('\\');
if (splittedName.Length > 0)
{
string sDomain = splittedName[0].ToString();
return (splittedName.Length > 1) ? splittedName[1].ToString().Trim().ToUpper() : splittedName[0].ToString().Trim().ToUpper();
}
}
return string.Empty;

Sachin SinghRank #66 · 26.2K reputationPosted Jan 7, 2021, 12:39 AM EST
Ramachandran MRank #2,660 · 522 reputationPosted Jan 7, 2021, 1:44 AM EST
if (HttpContext.Current.User != null)
{
sCurrentUserName = HttpContext.Current.User.Identity.Name.ToString();
}
if (sCurrentUserName == string.Empty)
sCurrentUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
if (sCurrentUserName == string.Empty)
sCurrentUserName = Environment.UserName;
Sachin SinghRank #66 · 26.2K reputationPosted Jan 7, 2021, 3:43 AM EST
Ramachandran MRank #2,660 · 522 reputationPosted Jan 7, 2021, 5:04 AM EST
Sachin SinghRank #66 · 26.2K reputationPosted Jan 7, 2021, 5:32 AM EST