简体   繁体   English

为什么我的MVC3网页没有向IIS Express发送Windows凭据?

[英]Why is my MVC3 web page not sending Windows credentials to IIS Express?

I have been struggling with getting Windows Authentication to work with my MVC3 application in development (VS 2010 SP1), with no real luck so far. 我一直在努力让Windows身份验证与我的MVC3应用程序一起开发(VS 2010 SP1),到目前为止还没有真正的运气。 I am running XP on my dev machine (no money until next year for an upgrade), if that makes a difference. 我在我的开发机器上运行XP(直到明年没有钱进行升级),如果这有所不同。 I should also mention I am using IIS Express as the default web development server from VS 2010. 我还应该提到我使用IIS Express作为VS 2010的默认Web开发服务器。

I started with an empty MVC3 app awhile back, as I didn't have the Intranet template available from the VS menu until I upgraded the MVC3 tools yesterday (OK, I was a little slow). 我开始使用一个空的MVC3应用程序,因为我没有从VS菜单中获得Intranet模板,直到我昨天升级了MVC3工具(好吧,我有点慢)。 Once I installed and inspected that template, I added a reference to DirectoryServices to my project and added the bit of code that displays the current logged-on user in the upper right corner of the page. 一旦我安装并检查了该模板,我就将DirectoryServices的引用添加到了我的项目中,并在页面的右上角添加了显示当前登录用户的代码。 According to the graphics, it should now say "Welcome PCE\\dnewman!" 根据图形,它现在应该说“欢迎PCE \\ dnewman!”

I followed the excellent instructions in this post: IIS Express Windows Authentication and did make some headway. 我遵循了这篇文章中的优秀说明: IIS Express Windows身份验证并确实取得了一些进展。 However, I now get the 401.2 error from IIS Express, telling me I am not authorized... 但是,我现在从IIS Express收到401.2错误,告诉我我没有被授权......

So, I went in to my project properties and set Anonymous Authentication to Enabled. 所以,我进入了我的项目属性并将Anonymous Authentication设置为Enabled。 Now I can access the web page, but what I see in the upper right corner of my page is "Welcome !" 现在我可以访问该网页,但我在页面右上角看到的是“欢迎!” -- no username. - 没有用户名。

I tried this with both IE and Firefox, with the same result. 我尝试使用IE和Firefox,结果相同。 What the $#^&! 什么$#^&! am I missing here? 我在这儿失踪了? It seems I am not logged in to Windows!! 好像我没有登录到Windows !! Where do I need to start looking for the problem? 我在哪里开始寻找问题?

At a previous employer a couple of years back, I wrote a Windows Forms app that authenticated the user with their Windows logon credentials. 在几年前的前雇主,我写了一个Windows窗体应用程序,用他们的Windows登录凭据对用户进行身份验证。 In that case, I had to take special care to both send the credentials and then to explicitly authenticate them on the service end. 在这种情况下,我必须特别注意发送凭据,然后在服务端显式验证它们。 Is there something I have to do to make the browser include credentials with every GET or POST? 我是否需要做些什么来使浏览器包含每个GET或POST的凭据?

By request, here's the contents of my web.config, with apologies for all the Glimpse config stuff. 根据请求,这是我的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>

I am more than willing to divulge more details as needed, but I really don't even know where to start looking. 我非常愿意根据需要透露更多细节,但我真的不知道从哪里开始寻找。 Every post or article I can find seems to assume this part just happens as part of the Windows/MVC3/ASP.NET setup. 我能找到的每篇文章或文章似乎都认为这部分只是作为Windows / MVC3 / ASP.NET设置的一部分而发生的。

Thanks, Dave 谢谢,戴夫

If you follow all the recommendations in the referenced post, you'll end up with a non-working mess, like I did. 如果你遵循引用帖子中的所有建议,你最终会得到一个非工作的混乱,就像我做的那样。 Each answer has its own merit, but applying all of them only ends in frustration. 每个答案都有自己的优点,但应用所有答案只会以挫败感结束。

The post from Microsoft that answered all questions and got me working is here: How to Create an Intranet Site Using ASP.NET MVC 回答所有问题并让我工作的Microsoft的帖子在这里: 如何使用ASP.NET MVC创建Intranet站点

Save this link, it's golden... 保存此链接,这是金色的......

I also found the "Add Deployable Dependencies" option can break Windows authentication. 我还发现“Add Deployable Dependencies”选项可以破坏Windows身份验证。 If I selected the "ASP.NET Web Pages with Razor syntax" option in the "Add Deployable Dependencies" dialog box, it immediately broke Windows authentication and seemed to go back to forms authentication -- I got a 404 error "The resource cannot be found" looking for /Account/Login. 如果我在“添加可部署依赖项”对话框中选择了“带有Razor语法的ASP.NET网页”选项,它会立即破坏Windows身份验证并似乎返回到表单身份验证 - 我收到404错误“资源不能是发现“寻找/帐户/登录。 I didn't have to deploy it, just selecting that option broke it. 我没有必要部署它,只是选择该选项打破了它。 The only way to fix it then is to start over. 解决它的唯一方法是重新开始。 I was unable to remove enough of anything to get it to start working again, and I was unable to determine what change was made that caused this behavior. 我无法删除任何东西以使其重新开始工作,而我无法确定导致此行为的更改。

This blog post saved the day: How to Deploy an ASP.NET MVC 3 App to Web Hosting with "\\bin Deployment" - it shows which assemblies are needed and how to get them included with your web app when you deploy it WITHOUT using the "Add Deployable Dependencies" nonsense. 这篇博客文章保存了这一天: 如何使用“\\ bin部署”将ASP.NET MVC 3应用程序部署到Web主机 - 它显示了在部署它时不需要使用哪些程序集以及如何将它们包含在Web主机中“添加可部署的依赖关系”废话。

I hope this saves somebody the hours I spent trying to get it all to work. 我希望这能节省一些人花费的时间来试图让它全部运转起来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IIS Express为什么会向我的一个.Web项目发送426升级要求错误? - Why is IIS Express sending 426 Upgrade Required errors for requests to one my .Web projects? 默认情况下,在Visual Studio 2010(MVC3)Web项目中使用IIS Express? - Use IIS Express by default in Visual Studio 2010 (MVC3) web projects? Visual Web Developer 2008 Express中的ASP.NET MVC3 - ASP.NET MVC3 in Visual Web Developer 2008 Express 关闭Visual Studio后继续运行I​​IS Express和我的网页 - Keep running IIS Express and my web page after closing visual studio 在访问IIS Web应用程序时提示Windows登录凭据 - Prompt for windows login credentials when accessing IIS web application 使用自定义页面处理IIS6,IIS7,ASP.NET MVC3中的500个错误的权威指南 - Definitive Guide to Handling 500 Errors in IIS6, IIS7, ASP.NET MVC3 with Custom Page 在MVC3中从列表到Web页面显示Blob图像对象 - Displaying blob images objects from a list to a web page in mvc3 ASP.NET 5 MVC:无法连接到 Web 服务器“IIS Express” - ASP.NET 5 MVC: unable to connect to web server 'IIS Express' 在MVC Web应用程序的IIS Express中的端口443上强制使用SSL - Forcing SSL on port 443 in IIS Express for an MVC web application 使用MVC3进行页面导航 - Page Navigation with MVC3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM