HttpContext.Current.User.Identity.Name为Empty [英] 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
任何可以提供帮助的人?或者知道我在哪里可以找到视觉工作室开发中心的设置,所以我可以检查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的博客文章 Recipe:在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身份验证,但我有< authentication mode =Windows/>
在web.config的< system.web>
部分,我没有阻止匿名访问。最后一部分是关键。 您需要阻止匿名访问以确保浏览器发送凭据。
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为Empty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!