是否可以在不编辑web.config的情况下获取ACS声明

本文关键字:情况下 获取 ACS 声明 config web 编辑 是否 | 更新日期: 2023-09-27 18:26:08

是否可以在不编辑web.config的情况下为azure ACS设置领域URL、声明类型等?你能以某种方式以编程方式设置这些必需的元素吗?

编辑:具体来说,我想摆脱这个:

<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部分?或者是否有信息传递到被覆盖的身份验证方法中,我可以使用它来执行自己的身份验证?

是否可以在不编辑web.config的情况下获取ACS声明

为了从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部分也被完全删除。

是的,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

处理FederatedAuthentication类的FederationConfigurationCreated事件,例如在Global.asax:的Application_Start中

void Application_Start(object sender, EventArgs e)
{
    FederatedAuthentication.FederationConfigurationCreated += FCC;
}
private void FCC(object sender, FederationConfigurationCreatedEventArgs e)
{
    e.FederationConfiguration.WsFederationConfiguration.PassiveRedirectEnabled = true;
    e.FederationConfiguration.WsFederationConfiguration.Issuer = "https://mynamespace.accesscontrol.windows.net/v2/wsfederation";
    e.FederationConfiguration.WsFederationConfiguration.Realm = "http://localhost:81/";
    e.FederationConfiguration.WsFederationConfiguration.RequireHttps = false;
}