我一直在努力使Windows身份验证与我的MVC3应用程序在开发(VS 2010 SP1)中一起工作,迄今为止没有真正的运气。我在我的开发机器上运行XP(明年之前没有钱用于升级),如果这有所作为。我还应该提到我使用IIS Express作为VS 2010的默认Web开发服务器。为什么我的MVC3网页不向IIS Express发送Windows凭据?
我刚开始时使用了一个空的MVC3应用程序,因为我没有从VS菜单提供的Intranet模板,直到我升级MVC3工具昨天(好吧,我有点慢)。一旦我安装并检查了该模板,我添加了对我的项目的DirectoryServices引用,并在页面右上角添加了显示当前登录用户的代码位。根据图形,现在应该说“Welcome PCE \ dnewman!”
我遵循了这篇文章中的优秀说明:IIS Express Windows Authentication,并取得了一些进展。但是,我现在从IIS Express得到401.2错误,告诉我我没有授权...
所以,我进入我的项目属性,并将匿名身份验证设置为启用。现在我可以访问网页,但我在页面右上角看到的是“欢迎!” - 没有用户名。
我试过这个IE和Firefox,结果都一样。什么$#^ &!我在这里想念吗?看来我没有登录到Windows!我需要从哪里开始寻找问题?
在过去几年的雇主中,我写了一个Windows窗体应用程序,用它们的Windows登录凭证对用户进行身份验证。在这种情况下,我必须特别注意发送凭证,然后在服务端显式验证它们。有什么我必须做的使浏览器包含每个GET或POST的凭据?
根据要求,这里是我的web.config的内容,道歉为所有Glimpse配置的东西。
<?xml version="1.0"
encoding="utf-8"?>
<configuration>
<configSections>
<section name="glimpse"
type="Glimpse.Core.Configuration.GlimpseConfiguration" />
</configSections>
<appSettings>
<add key="ClientValidationEnabled"
value="true" />
<add key="UnobtrusiveJavaScriptEnabled"
value="true" />
</appSettings>
<system.web>
<compilation debug="true"
targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<trace writeToDiagnosticsTrace="true"
enabled="true"
pageOutput="false" />
<httpModules>
<add name="Glimpse"
type="Glimpse.Core.Module" />
</httpModules>
<httpHandlers>
<add path="glimpse.axd"
verb="GET,POST"
type="Glimpse.Core.Handler" />
</httpHandlers>
</system.web>
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="false"/>
<windowsAuthentication enabled="true" />
</authentication>
</security>
<modules runAllManagedModulesForAllRequests="true">
<add name="Glimpse"
type="Glimpse.Core.Module,Glimpse.Core"
preCondition="integratedMode" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="Glimpse"
path="glimpse.axd"
verb="GET,POST"
type="Glimpse.Core.Handler,Glimpse.Core"
preCondition="integratedMode" />
</handlers>
</system.webServer>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IReporting"
maxBufferSize="1024000"
maxBufferPoolSize="1000000"
maxReceivedMessageSize="1024000">
<readerQuotas maxDepth="200"
maxStringContentLength="65536"
maxArrayLength="32768"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None" />
</binding>
<binding name="normalBinding">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint name="tcpAdminServiceEndpoint"
address="net.tcp://PCESRV22.pce.local:9000/ProductionMonitor/AdminService"
binding="netTcpBinding"
bindingConfiguration="normalBinding"
contract="Contracts.IAdmin" />
<endpoint name="tcpMasterDataServiceEndpoint"
address="net.tcp://PCESRV22.pce.local:9010/ProductionMonitor/MasterDataService"
binding="netTcpBinding"
bindingConfiguration="normalBinding"
contract="Contracts.IMasterData" />
<endpoint name="tcpReportingServiceEndpoint"
address="net.tcp://PCESRV22.pce.local:9030/ProductionMonitor/ReportingService"
binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IReporting"
contract="Contracts.IReporting" />
</client>
</system.serviceModel>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc"
publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0"
newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<glimpse enabled="true" />
</configuration>
我很愿意根据需要泄露更多细节,但我真的不知道从哪里开始寻找。我能找到的每篇文章或文章似乎都假设这部分只是作为Windows/MVC3/ASP.NET安装程序的一部分而发生。
谢谢,戴夫
您是否禁用了此答案中提到的匿名身份验证? http://stackoverflow.com/questions/4762538/iis-express-windows-authentication/7168308#7168308 – jrummell
我秒禁用匿名身份验证。你提到你使用IIS Express?如果你调试应用程序会发生什么?在你的构造函数中加入一个断点,让我知道你在'this.User.Identity'中找到了什么。 – Rastapopulous
至于第一条评论,是的。这是我在上面提到的同一篇文章中提到的。当没有工作,我重新启用它看看会发生什么,并得到空白的用户名。当我启用匿名进行调试并查看this.User.Identity时,我会从我的观察中得到我所期望的,一个空字符串。当我禁用匿名身份验证时,应用程序在它遇到我的断点(在Global.asax.cs中的Application_Start)之前死于401.2错误 – DaveN59