2012-02-27 35 views
8

是否有可能爲azure ACS設置領域URL,聲明類型等而不編輯web.config?你能以某種方式編程設置這些必需的元素嗎?是否可以在不編輯web.config的情況下獲得ACS聲明?

編輯: 具體來說,我想擺脫這種:

<federatedAuthentication> 
    <wsFederation passiveRedirectEnabled="true" issuer="https://mynamespace.accesscontrol.windows.net/v2/wsfederation" realm="http://localhost:81/" requireHttps="false" /> 
</federatedAuthentication> 

基本上,我不希望在web配置所指定的境界,而是在某個地方的代碼做。我嘗試覆蓋ClaimsAuthenticationManager並將部分註釋掉與FederatedAuthentication相關的代碼。我重寫的身份驗證代碼被擊中,但它不包含任何索賠。我假設這是因爲FederatedAuthentication是一箇中介,它在它正常進入重寫的ClaimsAuthenticationManager之前執行自己的身份驗證。有沒有辦法以類似的方式覆蓋FederatedAuthentication部分?或者是否有信息傳入重寫的身份驗證方法,我可以使用它來執行我自己的身份驗證?

回答

9

要從web配置該XML行,我做我自己的WSFederationAuthenticationModule覆蓋舊的,像這樣:

public class CustomWSFederationAuthenticationModule : WSFederationAuthenticationModule 
{ 
    protected override void InitializePropertiesFromConfiguration(string serviceName) 
    { 
     this.Realm = "http://localhost:81/"; 
     this.Issuer = "https://acsnamespace.accesscontrol.windows.net/v2/wsfederation"; 
     this.RequireHttps = false; 
     this.PassiveRedirectEnabled = true; 
    } 
} 

而web.config中的重要組成部分:

<modules runAllManagedModulesForAllRequests="true"> 
    <add name="WSFederationAuthenticationModule" type="CustomModuleLocation.CustomWSFederationAuthenticationModule, CustomModuleLocation" preCondition="managedHandler"/> 
    <add name="SessionAuthenticationModule" type="Microsoft.IdentityModel.Web.SessionAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" /> 
</modules> 

另外,XML的federatedAuthentication節已被除去entirel年。

+1

在我的世界裏工作就像一個魅力。謝謝! – 2016-03-23 02:11:26

1

是的,FedUtil這樣做。它是Windows Identity Foundation(WIF)SDK附帶的實用程序,您可以從Visual Studio中調用它。

http://msdn.microsoft.com/en-us/library/ee517285.aspx

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=4451

編輯:我可能誤解了你的問題。 FedUtil是一個爲你配置你的web.config的工具。如果你想用代碼來配置應用程序,那也是可以的。 MSDN上的WIF文件應說明如何做到這一點:

http://msdn.microsoft.com/en-us/library/ee766446.aspx

+0

第二件事是我所尋找的更多。我在自定義的令牌處理程序上找到了此頁: http://msdn.microsoft.com/en-us/library/ee517261.aspx 非常有幫助。 – 2012-02-29 16:21:20

相關問題