我最近将访问控制服务合并到我们的应用程序中。它在开发结构中 100% 正常工作(没有抛出异常)。但是,在实际的 azure 网站上运行它时,它无法加载网站。
我在整个网站上添加了记录调用,唯一触发的是 OnStart() 方法中 WebRole 的开头和结尾。我已经将日志记录添加到它应该命中的控制器中,并且它永远不会被调用。我还添加了登录到“InitializePropertiesFromConfiguration”方法,该方法在我的自定义 WSFederationAuthenticationModule 中被覆盖,这让我相信它在 Web 配置中执行某些操作时遇到问题(添加我的自定义 STS 处理程序等)。下面是我的应用程序的 web.config,如果有人知道是什么可能导致诸如此类的问题,或者至少可以尝试一些东西,我将非常感激。更糟糕的是,工作防火墙问题意味着我无法远程进入 azure 机器以查看向 Windows 日志抛出的错误。我'
<?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=152368
-->
<configuration>
<configSections>
<section name="microsoft.identityModel" type="Microsoft.IdentityModel.Configuration.MicrosoftIdentityModelSection, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<globalization culture="en" uiCulture="en"/>
<httpRuntime requestValidationMode="2.0" />
<authentication mode="None" />
<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.Helpers, Version=2.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=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<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.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="TBX.Common.Web"/>
<add namespace="TBX.Pulse.Web"/>
</namespaces>
</pages>
<httpModules>
<add name="WSFederationAuthenticationModule" type="TBX.Pulse.Web.Authentication.CustomWSFederationAuthenticationModule, TBX.Pulse.Web"/>
<add name="SessionAuthenticationModule" type="Microsoft.IdentityModel.Web.SessionAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<add name="WSFederationAuthenticationModule" type="TBX.Pulse.Web.Authentication.CustomWSFederationAuthenticationModule, TBX.Pulse.Web" preCondition="managedHandler"/>
<add name="SessionAuthenticationModule" type="Microsoft.IdentityModel.Web.SessionAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
</modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="TBX.Pulse.Web.Scripts.ButtonClickAnimationAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
<extensions>
<behaviorExtensions>
<add name="federatedServiceHostConfiguration" type="Microsoft.IdentityModel.Configuration.ConfigureServiceHostBehaviorExtensionElement, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</behaviorExtensions>
</extensions>
<protocolMapping>
<add scheme="http" binding="ws2007FederationHttpBinding" />
</protocolMapping>
<bindings>
</bindings>
</system.serviceModel>
<microsoft.identityModel>
<service>
<claimsAuthorizationManager type="TBX.Pulse.Web.Authorization.CustomClaimsAuthorizationManager" />
<claimsAuthenticationManager type="TBX.Pulse.Web.Authentication.CustomClaimsAuthenticationManager" />
<securityTokenHandlers>
<remove type="Microsoft.IdentityModel.Tokens.Saml2.Saml2SecurityTokenHandler, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add type="TBX.Pulse.Web.Authentication.CustomSecurityTokenHandler, TBX.Pulse.Web"/>
</securityTokenHandlers>
<certificateValidation certificateValidationMode="None" />
<serviceCertificate>
<certificateReference x509FindType="FindBySubjectName" findValue="PulseLoginCert" />
</serviceCertificate>
</service>
</microsoft.identityModel>
</configuration>
编辑:在搞砸了这个之后,我发现了 2 个问题,一个我已经修复,另一个仍然有待解决:第一个问题是 web 配置需要这个:因为我已经切换到 https
第二个问题与加载证书有关:
注释掉这部分代码,它运行良好。仍然存在它不起作用。显而易见的问题是它无法加载此证书。我尝试通过指纹加载,但无济于事。我最好的猜测是 Azure 上的 storeLocation 或 storeName 不正确。我已将证书添加到“证书”文件夹中,但找不到它。我会弄乱这些并报告回来。
EDIT2:找到了第二个问题的原因:我忘记将证书添加到网络角色,这个网站对解决这个问题有很大帮助:http: //blogs.msdn.com/b/jnak/archive/2009/ 12/01/how-to-add-an-https-endpoint-to-a-windows-azure-cloud-service.aspx