2012年11月29日

[Azure]一些ACS相關的問題 (1)

  1. 使用VS2012使用ACS v2.0驗證時,透過Identity and Security…設定完ACS Namespace之後,在本機跑都很正常,但是放到雲端上就一堆錯誤。這問題主要是因為目前使用Identity and Security時,他會設定使用.Net Framework 4.5版本的assembly,但是現在除非我們在cscfg中去指定osfamily=”3”,使用Windows 2012 Server才會有.Net 4.5支援,否則的話只能使用.Net Framework 4.0。

因此我們必須手動修改相關設定,讓程式使用.Net framework 4.0。

首先設定完ACS後,打開VS2012,確定Target Framework是4.0

image

接下來要修改web.config,首先要將configuration section預設使用的<security.identityModel>與<security.identityModel.services>註解掉,新增以下這一行:

<section name="microsoft.identityModel" type="Microsoft.IdentityModel.Configuration.MicrosoftIdentityModelSection, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

接著把下面的<security.identityModel>與<security.identityModel.services>整段mark掉,換成下面這一段:

<microsoft.identityModel>
  <service>
    <securityTokenHandlers>
      <securityTokenHandlerConfiguration>
        <audienceUris>
          <add value=http://{your URL}/ />
        </audienceUris>
        <issuerNameRegistry type="Microsoft.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
          <trustedIssuers>
            <add thumbprint="C75956CC7E0B8F90ED52A3AEF970465CD630F0E0" name=https://{ACS Namespace}.accesscontrol.windows.net/ />
          </trustedIssuers>
        </issuerNameRegistry>
      </securityTokenHandlerConfiguration>
    </securityTokenHandlers>
    <certificateValidation certificateValidationMode="None" />
    <federatedAuthentication>
      <cookieHandler requireSsl="false" />
      <wsFederation passiveRedirectEnabled="true" issuer=https://{ACS Namespace}.accesscontrol.windows.net/v2/wsfederation realm=http://{your URL}/ reply=http://{your URL}/” requireHttps="false" />
    </federatedAuthentication>
  </service>
</microsoft.identityModel>

然後設定runtime validation mode

<httpRuntime requestValidationMode="2.0" />

修改<system.webServer>如下:

<system.webServer>
  <modules>
    <!--<add name="WSFederationAuthenticationModule" type="System.IdentityModel.Services.WSFederationAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
    <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />-->
    <add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel" preCondition="managedHandler" />
    <add name="SessionAuthenticationModule" type="Microsoft.IdentityModel.Web.SessionAuthenticationModule, Microsoft.IdentityModel" preCondition="managedHandler" />

  </modules>

沒有留言:

Blog Archive

About Me