我需要在IIS中检索当前登录的用户ID,然后我将该ID传递给用于身份验证的功能。
public ActionResult Login(myLoginModel model)
{
System.Security.Principal.IPrincipal user;
user = System.Web.HttpContext.Current.User;
String name = user.Identity.Name.ToString();
AuthenticateUser(name)
}
我总是得到“name”的空值。我的web.config文件是:
<authentication mode="Windows"/>
<identity impersonate="true"/>
我在IIS管理器上禁用了匿名身份验证并启用了Windows身份验证。你能帮我解决这个问题吗?
答案 0 :(得分:0)
尝试让用户不是来自HttpContext
而是来自Controller
:
Controller.User.Identity.Name
或User.Identity.Name