Asp.net 为什么我的MVC3网页不向IIS Express发送Windows凭据?
我一直在努力让Windows身份验证与开发中的MVC3应用程序(VS 2010 SP1)配合使用,但到目前为止还没有真正的运气。我在我的开发机器上运行XP(明年之前没有钱升级),如果这有区别的话。我还应该提到,我正在使用IIS Express作为VS2010的默认web开发服务器 不久前,我开始使用一个空的MVC3应用程序,因为在昨天升级MVC3工具之前,我没有VS菜单中的Intranet模板(好吧,我有点慢)。安装并检查该模板后,我在项目中添加了对DirectoryServices的引用,并在页面右上角添加了显示当前登录用户的代码。根据图表,它现在应该说“欢迎PCE\dnewman!” 我遵循了这篇文章中的精彩指示:并取得了一些进展。然而,我现在从IIS Express得到401.2错误,告诉我我没有授权 因此,我进入我的项目属性并将匿名身份验证设置为Enabled。现在我可以访问该网页,但我在页面右上角看到的是“欢迎!”——没有用户名 我在IE和Firefox上都试过了,结果是一样的。什么是$#^&!我在这里失踪了吗?似乎我没有登录到Windows!!我需要从哪里开始寻找问题 几年前,我在以前的一家公司编写了一个Windows窗体应用程序,该应用程序使用用户的Windows登录凭据对用户进行身份验证。在这种情况下,我必须特别注意发送凭据,然后在服务端显式地对它们进行身份验证。我必须做些什么才能让浏览器在每次GET或POST中都包含凭据 根据请求,以下是我的web.config的内容,并对所有这些内容表示歉意Asp.net 为什么我的MVC3网页不向IIS Express发送Windows凭据?,asp.net,asp.net-mvc-3,windows-authentication,Asp.net,Asp.net Mvc 3,Windows Authentication,我一直在努力让Windows身份验证与开发中的MVC3应用程序(VS 2010 SP1)配合使用,但到目前为止还没有真正的运气。我在我的开发机器上运行XP(明年之前没有钱升级),如果这有区别的话。我还应该提到,我正在使用IIS Express作为VS2010的默认web开发服务器 不久前,我开始使用一个空的MVC3应用程序,因为在昨天升级MVC3工具之前,我没有VS菜单中的Intranet模板(好吧,我有点慢)。安装并检查该模板后,我在项目中添加了对DirectoryServices的引用,并在
<?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设置的一部分
谢谢,戴夫,如果你按照引用文章中的所有建议去做,你最终会像我一样,陷入一片混乱。每个答案都有自己的优点,但应用所有答案只会以失败告终 微软的帖子回答了所有问题,让我工作起来: 保存此链接,它是金色的 我还发现“添加可部署依赖项”选项可以破坏Windows身份验证。如果我在“添加可部署依赖项”对话框中选择“ASP.NET Web Pages with Razor syntax”选项,它会立即中断Windows身份验证,并似乎返回到窗体身份验证--我在查找/Account/Login时遇到404错误“找不到资源”。我不需要部署它,只是选择了这个选项就破坏了它。解决这个问题的唯一办法就是重新开始。我无法删除足够多的内容使其重新开始工作,也无法确定是什么更改导致了这种行为 这篇博文拯救了这一天:-它显示了需要哪些程序集,以及在部署web应用程序时如何将它们包含在web应用程序中,而不必使用“添加可部署依赖项”的废话
我希望这能帮某人节省我花在让它正常工作上的时间。您是否如回答中所述禁用了匿名身份验证?我支持禁用匿名身份验证。你提到你正在使用IIS express?如果调试应用程序会发生什么?在你的构造函数上设置一个断点,让我知道你在
this.User.Identity
中找到了什么关于第一条评论,是的,我找到了。我上面提到的同一篇文章也提到了这一点。当它不起作用时,我使它能够看到会发生什么,得到了空白用户名。当我在启用匿名的情况下调试它并查看这个.User.Identity时,我从观察中得到了一个空字符串。当我禁用匿名身份验证时,应用程序在到达我的断点(在Global.asax.cs中的Application_Start处)之前就会因401.2错误而死亡。顺便说一句,我需要启用匿名身份验证,因为我只希望保护站点中的某些页面。大多数网站都需要对所有人开放。@Dave您的Web.config中有
吗?我刚刚添加了可部署依赖项。转到我的部署,发现了所描述的404错误。假设我在设置中做错了什么。回到我的调试站点,发现它也停止了。只需点击该死的选项。我会试试你的建议+这篇文章帮助我解决了我的问题。您必须手动恢复“添加可部署依赖项”(来源:)造成的损坏。Microsoft没有提供关于您实际需要删除哪些文件的说明,但在从项目文件夹bin
和\u bin\u DeployableAssembly
中删除文件后,我的项目再次运行。另外请注意,内容已添加到web.config
(可能在其他地方添加)。谢谢。这对我有用。在我的WebAPI应用程序中,我为IIS express启用了“Windows身份验证”,但没有禁用匿名身份验证。我的User.Identity.Name是空字符串,直到我执行了后者。