2011-11-08 28 views
3

我一直在努力使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安装程序的一部分而发生。

谢谢,戴夫

+0

您是否禁用了此答案中提到的匿名身份验证? http://stackoverflow.com/questions/4762538/iis-express-windows-authentication/7168308#7168308 – jrummell

+0

我秒禁用匿名身份验证。你提到你使用IIS Express?如果你调试应用程序会发生什么?在你的构造函数中加入一个断点,让我知道你在'this.User.Identity'中找到了什么。 – Rastapopulous

+0

至于第一条评论,是的。这是我在上面提到的同一篇文章中提到的。当没有工作,我重新启用它看看会发生什么,并得到空白的用户名。当我启用匿名进行调试并查看this.User.Identity时,我会从我的观察中得到我所期望的,一个空字符串。当我禁用匿名身份验证时,应用程序在它遇到我的断点(在Global.asax.cs中的Application_Start)之前死于401.2错误 – DaveN59

回答

6

如果按照引用的所有职位的建议,你会最终有一个不工作的烂摊子,像我一样。每个答案都有自己的优点,但是应用所有答案只会以挫败感告终。

从微软的职位,回答所有的问题,并让我的工作是在这里:How to Create an Intranet Site Using ASP.NET MVC

保存这个链接,它是金色的......

我还发现“添加部署相关性”选项可以打破的Windows认证。如果我在“添加可部署的依赖关系”对话框中选择了“带有Razor语法的ASP.NET网页”选项,它立即破坏了Windows身份验证,似乎又回到了表单身份验证 - 我收到了404错误“该资源不能找到“寻找/帐户/登录。我不必部署它,只需选择该选项就可以打破它。解决这个问题的唯一方法就是重新开始。我无法移除足够的任何东西以使其重新开始工作,并且我无法确定导致此行为的变化。

这篇博文保存了一天:How to Deploy an ASP.NET MVC 3 App to Web Hosting with "\bin Deployment" - 它显示了需要哪些程序集以及如何在您使用“添加可部署的依赖项”废话时部署它,从而将它们包含在您的Web应用程序中。

我希望这可以节省一些人花费的时间,试图让这一切工作。

+0

我只是添加了可部署的依赖关系。去了我的部署,发现描述的404错误。假设我在安装过程中做了错误的事情。回到我的调试网站注意它也停止了。只需点击该死的选项。我会尝试你所建议的。 +1 – Doomsknight

+0

这篇文章帮助我解决了我的问题。您必须手动还原“Add Deployable Dependencies”(来源:http://msdn.microsoft.com/en-us/library/gg286946(v = vs.110).aspx)所造成的损害。微软没有提供关于你实际需要删除的文件的说明,但是从项目文件夹'bin'和'_bin_deployableAssemblies'中删除文件后,我的项目再次运行。还要注意内容被添加到'web.config'' '(也许在其他地方)。 – bennedich

+0

谢谢。这对我有效。在我的WebAPI应用程序中,我为IIS Express启用了“Windows身份验证”,但未禁用匿名身份验证。我的User.Identity.Name是空字符串,直到我做了后者。 – mwilson

相关问题