带有Windows身份验证的ASP.NET MVC Intranet应用程序,如何自动获取当前域用户?

e4r*_*dog 6 authentication asp.net-mvc windows-authentication

我需要我的MVC4应用程序来获取登录到机器的当前域用户自动登录到我的index.cshtml页面.

通过使用Authorize属性我需要保护的操作,应用程序的其余部分按预期工作.

我只需要对应用程序说"获取当前计算机登录用户,不保护任何内容并将用户带到登录页面".

web.config中:

<authentication mode="Windows" />
Run Code Online (Sandbox Code Playgroud)

像这样,用户在登录页面上是BLANK.

如果我尝试只将[授权]放在我的索引操作上,那么它会要求提供凭据,然后按照我的意愿继续,而不会在登录页面上保护任何内容.

有没有办法解决?

更新:

无论你做什么,似乎都没有办法绕过登录提示并让应用程序自动获取当前域用户并将其登录到应用程序中.

Mur*_*san 3

从MSDN检查这个

impersonate="true"一起添加

  <identity impersonate="true"/>
  <authentication mode="Windows" />
Run Code Online (Sandbox Code Playgroud)

然后使用

 ((HttpContext)context).User.Identity as WindowsIdentity
Run Code Online (Sandbox Code Playgroud)