2013-10-15 77 views
3

開發處理跟蹤數據的MVC站點。目標是使用MVC4並將其部署到運行SQL Server 2008和IIS 7.5的Windows 2008 R2服務器。這在域中運行。部署到遠程IIS 7.5的MVC4在訪問SQL Server時出現401.2錯誤

原始設置,工作,是使用Visual Studio 2012.2運行Windows 8,IIS 8(不表達),並與遠程SQL服務器交談的開發機器。開發沒有使用開發人員服務器發生。我能夠連接到網站,運行任何東西,而不會在任何日誌中出現明顯問題。

自2008年服務器部署到IIS 7.5後發生了問題。使用DefaultAppPool映射到ApplicationPoolIdentity,我創建了一個綁定*:80的Web站點並附加了部署。設置有:

Application pool: DefaultAppPool 
.Net Framework Version: 4.0 
Pipeline Mode: Integrated 
Pass-through authentication. 

測試設置顯示消息「應用程序池標識是有效的。」 我向網站添加一個虛擬目錄,並且測試設置顯示相同的消息。 我將目錄轉換爲應用程序,並且測試設置現在顯示錯誤消息「無效的應用程序路徑」。如果我使用我自己的憑證,那麼測試設置它顯示有效。

從遠程服務器上的IIS網站 - >應用程序 - >操作 - >瀏覽*:80 我自動收到我的主頁。瀏覽到包含對sql server的調用的頁面會給我一個錯誤401.2,它跟蹤到遠程機器上的404。

我在IIS服務器上安裝了Windows身份驗證,我在IIS AppPool\DefaultAppPool的SQL中創建了登錄名。我在數據庫中添加了相同的用戶db_readerdb_writer。我添加了身份以讀取/寫入並執行網站虛擬目錄的權限。

我已經閱讀了所有可以在我的搜索結果中找到的所有內容,並且所有內容都說明問題是Windows身份驗證未安裝或需要運行aspnet_regiis -i ...但我全部都完成了!我確信這是一個配置問題,但我無法弄清楚,並且在最近兩天裏竭盡全力解決這個問題。

的Web.config部分如下:

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    http://go.microsoft.com/fwlink/?LinkId=169433 
    --> 
<configuration> 
    <configSections> 

    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections> 
    <appSettings> 
    <add key="webpages:Version" value="2.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="PreserveLoginUrl" value="true" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5"> 
     <assemblies> 
     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     </assemblies> 
    </compilation> 
    <httpRuntime targetFramework="4.5" /> 
    <authentication mode="Windows" /> 
    <authorization> 
     <deny users="?" /> 
    </authorization> 
    <pages> 
     <namespaces> 
     <add namespace="System.Web.Helpers" /> 
     <add namespace="System.Web.Mvc" /> 
     <add namespace="System.Web.Mvc.Ajax" /> 
     <add namespace="System.Web.Mvc.Html" /> 
     <add namespace="System.Web.Optimization" /> 
     <add namespace="System.Web.Routing" /> 
     <add namespace="System.Web.WebPages" /> 
     </namespaces> 
    </pages> 
    <identity impersonate="true" /> 
    </system.web> 
    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <handlers> 
     <remove name="TestAsyncHttpHandler" /> 
     <add name="TestAsyncHttpHandler" path="*.svc" verb="*" type="System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
     <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> 
     <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> 
     <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> 
     <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> 
     <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> 
     <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /></handlers> 
     <modules> 
      <remove name="WebDAVModule" /> 
     </modules> 
    </system.webServer> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.4.0.0" newVersion="5.4.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.4.0.0" newVersion="5.4.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.4.0.0" newVersion="5.4.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    </entityFramework> 
    <connectionStrings> 
    <add name="PerfTrendDataEntities" connectionString="metadata=res://*/Models.PerfTrendDBModel.csdl|res://*/Models.PerfTrendDBModel.ssdl|res://*/Models.PerfTrendDBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=perftrenddb;initial catalog=PerfTrendData;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="TrendRestServiceBehavior"> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service name="PerformanceTrendDB.Web.SubmitResults.TrendRestService" behaviorConfiguration="TrendRestServiceBehavior"> 
     <endpoint name="BasicHttp" address="basic" binding="basicHttpBinding" bindingConfiguration="FileUploadConfig" contract="PerformanceTrendDB.Web.SubmitResults.ITrendRestService" /> 
     </service> 
    </services> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="FileUploadConfig" transferMode="StreamedRequest" /> 
     </basicHttpBinding> 
    </bindings> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
</configuration> 

所有這些配置的工程上的IIS 8在我的發展中,我不知道是否有應該有多大的差別與移動到IIS 7.5 ,我相當肯定它必須是從新機器與SQL服務器通信的問題。

編輯:添加日誌文件和跟蹤文件的操作,打開網站的

流量和點擊ManageUsers鏈接。管理用戶加載,然後API調用失敗。看起來好像很多錯誤都是由瀏覽器初次使用匿名發生的,然後使用憑證登錄......所以在配置中出現兩個錯誤來修復它。

日誌文件顯示:以簡潔片斷

2013-10-16 03:05:37 10.23.34.146 GET /PerformanceData - 80 - 10.24.158.125 Mozilla/5.0+(Windows+NT+6.2;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/30.0.1599.69+Safari/537.36 401 2 5 609 
2013-10-16 03:05:39 10.23.34.146 GET /PerformanceData - 80 AMR\gjmason 10.24.158.125 Mozilla/5.0+(Windows+NT+6.2;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/30.0.1599.69+Safari/537.36 200 0 0 2281 
2013-10-16 03:07:01 10.23.34.146 GET /PerformanceData/Home/ManageUsers - 80 - 10.24.158.125 Mozilla/5.0+(Windows+NT+6.2;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/30.0.1599.69+Safari/537.36 401 2 5 15 
2013-10-16 03:07:01 10.23.34.146 GET /PerformanceData/Home/ManageUsers - 80 AMR\gjmason 10.24.158.125 Mozilla/5.0+(Windows+NT+6.2;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/30.0.1599.69+Safari/537.36 200 0 0 484 
2013-10-16 03:07:03 10.23.34.146 GET /perftrenddb/api/UserManagement - 80 - 10.24.158.125 Mozilla/5.0+(Windows+NT+6.2;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/30.0.1599.69+Safari/537.36 401 2 5 1015 
2013-10-16 03:07:03 10.23.34.146 GET /perftrenddb/api/UserManagement - 80 AMR\gjmason 10.24.158.125 Mozilla/5.0+(Windows+NT+6.2;+WOW64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/30.0.1599.69+Safari/537.36 404 0 2 296 

跟蹤文件:

Summary (1st error) 
Url: http://perftrenddb:80/PerformanceData/Home/ManageUsers 
App Pool: DefaultAppPool 
Authentication: NOT_AVAILABLE 

Summary (2nd error - same details) 
Url: http://perftrenddb:80/perftrenddb/api/UserManagement 
App Pool: ASP.NET v4.0 Classic 
Authentication: NOT_AVAILABLE 

Summary (3rd error - from a STATUS_CODE 404) 
Url: http://perftrenddb:80/perftrenddb/api/UserManagement 
App Pool: ASP.NET v4.0 Classic 
Authentication: Negotiate 

所以三件事?

  1. 嘗試以匿名用戶身份登錄,或者是模擬嘗試?正常?
  2. 固定,請參閱解決方案2)api調用會去http://perftrenddb:80/perftrenddb/api/UserManagement,而不是我設置它的方式,而不是它在我的本地計算機上運行的方式。
  3. 應用程序池更改爲Classic而不是使用Integrated Pipeline的DefaultAppPool,是否有問題?

我可以回答第二個和第三個錯誤跟蹤,因爲那個在JS文件中。當我在開發環境中工作時,這是我的錯(這是我第一次進入Web開發,我通常堅持使用應用程序庫!)。我確實有這個部分的解決方案...它已經讓我的網站工作,雖然我仍然得到第一個問題和我不明白的App Pool轉換的錯誤/痕跡。

我討厭奇怪的問題我不明白所以任何洞察修復401.2匿名登錄問題將是偉大的!

解決方案2 要解決上下文前綴對我們菜鳥在那裏,硬編碼我們的虛擬目錄名稱存在,消除了開發者服務器/ IIS快遞/ IIS部署問題的修復程序。

添加到您的_Layout.cshtml或母版頁:

<script type="text/javascript"> 
     var config = { 
      contextPath: '@Url.Content("~")' 
     } 
    </script> 

然後在您的JS文件中加入:

var apiUri = config.contextPath + "api/MyWebApi"; 

哪裏MyWebApi是您正在訪問的API控制器的名稱。你現在可以叫你getJSON沒有問題,即

$.getJSON(apiUri, null).success(/* Your code */); 
+0

這不是一個SQL身份驗證問題。在你的應用程序運行之前,這是一件輕而易舉的事情。您提到Web服務器位於n個Active Directory域中。你能告訴我們更多關於你的網站身份驗證設置嗎? – Kev

+0

@Kev它是一個公司站點,McAfee正在運行,並且防火牆設置爲服務器上的HTTP和HTTP請求打開。我對我設置的服務器具有管理訪問權限,但除查看它們外無法訪問公司策略。如果有特定的東西我可以查找和分享我會,但我沒有發現任何設置IIS服務器的具體問題。 –

+1

是否可以在IIS中設置失敗的請求追蹤? –

回答

1

至於我也明白了,我可以在微軟網站看到401.2錯誤是因爲

認證不需要執行,因爲服務器和客戶端可能 不同意身份驗證協議

另外我可以猜測,也可能有權限的問題也。

您可以使用Microsoft提供下列工具來診斷問題

Authentication and Access Control Diagnostics 1.0

IIS Diagnostics Toolkit

希望這可能是有益的某一個誰也面臨同樣的問題。

+0

這些鏈接現在都已經死了:( –

+0

「身份驗證和訪問控制診斷」== authdiag.exe,受IIS6支持,但不支持IIS7 +。它不再可以從microsoft.com獲得,但是在cnet上有一個列表(我想不信任,但我沒有使用IIS6,YMMV) – Emyr

相關問題