C# 是否可以在不编辑web.config的情况下获取ACS索赔?

C# 是否可以在不编辑web.config的情况下获取ACS索赔?,c#,azure,wif,claims-based-identity,acs,C#,Azure,Wif,Claims Based Identity,Acs,是否可以在不编辑web.config的情况下为azure ACS设置域URL、声明类型等?您能否以编程方式设置这些必需的元素 编辑: 具体来说,我想摆脱这个: <federatedAuthentication> <wsFederation passiveRedirectEnabled="true" issuer="https://mynamespace.accesscontrol.windows.net/v2/wsfederation" realm="http://lo

是否可以在不编辑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是一个中介,它在到达覆盖的ClaimsAuthenticationManager之前执行自己的身份验证。有没有办法以类似的方式覆盖FederatedAuthentication部分?或者是否有信息传递到重写的authenticate方法中,我可以使用该方法执行我自己的身份验证?

是的,FedUtil会这样做。它是Windows身份基础(WIF)SDK附带的实用工具,您可以从VisualStudio./P>调用它。

编辑:我可能误解了你的问题。FedUtil是一个为您配置web.config的实用程序。如果您想用代码配置应用程序,也可以这样做。MSDN上的WIF文档应说明如何做到这一点:


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

处理FederationConfigurationCreated事件的federatedAuthentication类,例如在应用程序中启动Global.asax:

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;
}

第二件事是我一直在寻找的。我发现自定义令牌处理程序的这一页非常有用。在我的世界里,它就像一个符咒。非常感谢。