把它写成一个问题并自己回答,因为我有两个步骤来解决这个问题,而这个问题并不是一起提供的.
正在使用Visual Studio 2012在ASP.Net MVC 4 [使用剃刀视图的互联网应用程序]中开发应用程序.
默认的web.config条目<authentication>如下:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
Run Code Online (Sandbox Code Playgroud)
我需要为应用程序进行Windows身份验证.因此,将模式更改为Windows
<authentication mode="Windows" />
Run Code Online (Sandbox Code Playgroud)
用上面的设置,HttpContext.User.Identity.IsAuthenticated当时false HttpContext.User.Identity.Name是空字符串.