在使用visual studio时,如何在控制器代码中捕获httpcontext用户信息

时间:2010-01-25 20:53:05

标签: asp.net-mvc windows-authentication httpcontext

我问this question,它允许我使用以下方式捕获用户:

string userName = this.HttpContext.User.Identity.Name;

在我的控制器代码中。

我遇到的一个问题是,在visual studio中进行测试时,它会显示为空字符串。我想跟踪这个字段以进行测试。

无论如何在我的机器上的本地ASP.net网络服务器进程中有这项工作,所以它会在我的服务器上模仿Windows身份验证吗?

1 个答案:

答案 0 :(得分:0)

在IIS下运行应用程序并在web.config中设置Windows身份验证。

    <authentication mode="Windows">