问题描述:
做web登陆界面,调试时需要获取本机登陆名
public static string GetCurrentNTID()
{
string identityName = HttpContext.Current.User.Identity.Name;
int splitIndex = identityName.IndexOf('\\');
return splitIndex > -1 ? identityName.Substring(splitIndex + 1) : identityName;
}
但是HttpContext.Current.User.Identity.Name;获取到的对象一直为null
解决方法:
设置文件属性如下:
将windows authentication属性设为enable,得以解决。