HttpContext.Current.User.Identity.Name 为空 [英] HttpContext.Current.User.Identity.Name is Empty
问题描述
我有一个 Silverlight 应用程序(使用 MVC),当我在 Visual Studio 中构建时,使用 Visual Studio 开发中心,没有问题,HttpContext.Current.User.Identity.Name
有一个值
I have a Silverlight application (using MVC) and when i'm building in visual studio, using Visual Studio Development center, there's no problem, the HttpContext.Current.User.Identity.Name
has a Value
但是当我在 IIS 7.5 中使用同一个项目时(我使用的是 Windows 7),HttpContext.Current.User.Identity.Name
保持为空
But when i'm using the same project with IIS 7.5 (i'm using Windows 7), HttpContext.Current.User.Identity.Name
stays empty
谁能帮忙?或者知道在哪里可以找到 Visual Studio 开发中心的设置,以便检查 IIS 中的问题?
Anyone who can help? Or knows where i can find the settings from the visual studio Development center, so i can check what's wrong in IIS?
推荐答案
过去几天我一直在努力解决这个问题.
I struggled with this problem the past few days.
我建议阅读 Scott Guthrie 的博客文章 秘诀:在 Intranet ASP.NET Web 应用程序中启用 Windows 身份验证
I suggest reading Scott Guthrie's blog post Recipe: Enabling Windows Authentication within an Intranet ASP.NET Web application
对我来说,问题是虽然我在 IIS 中启用了 Windows 身份验证并且我有
部分,我没有阻止匿名访问.最后一部分是关键.您需要防止匿名访问以确保浏览器发送凭据.
For me the problem was that although I had Windows Authentication enabled in IIS and I had <authentication mode="Windows" />
in the <system.web>
section of web.config, I was not preventing anonymous access. This last part was the key. You need to prevent anonymous access to ensure that the browser sends the credentials.
您可以在控制面板中配置 IIS,以便您的站点(或机器)使用 Windows 身份验证并拒绝匿名访问,或者您可以将以下内容添加到 system.web 部分的 web.config 中:
You can either configure IIS in Control Panel so that your site (or machine) uses Windows authentication and denies anonymous access or you can add the following to your web.config in the system.web section:
<authentication mode="Windows" />
<authorization>
<deny users="?"/>
</authorization>
这篇关于HttpContext.Current.User.Identity.Name 为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!