带有Windows身份验证的ASP.NET MVC Intranet应用程序,如何自动获取当前域用户? [英] ASP.NET MVC intranet app with windows authentication, how to get the current domain user automatically?

查看:46
本文介绍了带有Windows身份验证的ASP.NET MVC Intranet应用程序,如何自动获取当前域用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need my MVC4 app to get the current domain user that is logged on to the machine automatically logged in in my index.cshtml page.

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

the rest of the application works as intended by using the Authorize attribute the actions i need secured.

我只需要对应用说让当前机器登录用户,不要保护任何东西并将用户带到登陆页面".

I just need to say to the app "get the current machine logged in user , dont secure anything and take the user to the landing page".

web.config:

web.config:

<authentication mode="Windows" />

像这样,用户在着陆页上是空白的.

like this the user is BLANK on the landing page.

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

If i try to put just [Authorize] on my index action then it asks for credentials and then continues as i want, without securing anything on the landing page.

有什么办法可以解决这个问题吗?

Is there any way around this?

更新:

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

No matter what you do , it seems that there is no way to bypass the login prompt and make the application automatically get the current domain user and log him in the app.

推荐答案

MSDN

Check this from MSDN

添加 impersonate="true" 连同它

  <identity impersonate="true"/>
  <authentication mode="Windows" />

然后使用

 ((HttpContext)context).User.Identity as WindowsIdentity

这篇关于带有Windows身份验证的ASP.NET MVC Intranet应用程序,如何自动获取当前域用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆