【问题标题】:FederatedAuthentication.FederationConfigurationCreated event not workingFederatedAuthentication.FederationConfigurationCreated 事件不起作用
【发布时间】:2014-01-29 09:07:21
【问题描述】:

我目前在我的 MVC 5 应用程序中有一个工作声明环境,它静态定义声明授权管理器。

但是我希望能够动态设置我的声明授权管理器,以便我可以使用 autofac 注入一些服务。

我在 Application_Start 方法中订阅了 FederatedAuthentication.FederationConfigurationCreated 事件,但它从未被调用,因此没有声明身份验证管理器。

如果我在事件句柄设置代码处断点,则会列出所有其他模块(因为我仍然静态定义它们)。

有人知道什么地方出了问题吗?

【问题讨论】:

    标签: asp.net asp.net-mvc wif asp.net-mvc-5 claims-based-identity


    【解决方案1】:

    我也无法触发 FederationConfigurationEventCreated 事件。原来我在连接事件之前调用了一堆联邦启动代码(IdentityConfig.ConfigureIdentity())——我的错!

    【讨论】:

      【解决方案2】:

      我执行以下步骤:

      AppStart

      ...
      using System.IdentityModel.Services.Configuration;
      using System.IdentityModel.Services;
      
      protected void Application_Start()
       ...
       FederatedAuthentication.FederationConfigurationCreated += FederatedAuthentication_FederationConfigurationCreated;      
      }
      
      void FederatedAuthentication_FederationConfigurationCreated(object sender, FederationConfigurationCreatedEventArgs e)
      {
                  // Replace the below with your implementation
          throw new NotImplementedException();
      }
      

      Web.config

      <configuration>
        <configSections>
         ...
          <section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
          <section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
          ...
        <system.identityModel.services>
          <federationConfiguration>
            <cookieHandler/>
          </federationConfiguration>
        </system.identityModel.services>
      </configuration>
      

      我发现这篇文章在实现时非常有用。

      http://dotnetcodr.com/2013/03/07/claims-based-authentication-in-net4-5-mvc4-with-c-external-authentication-with-ws-federation-part-1/

      更新

      我在system.identityModel 配置中也有以下内容。

        <system.identityModel>
          <identityConfiguration>
            <claimsAuthenticationManager type="namespace.webproject.CustomClaimsTransformer,namespace.webproject" />
            <claimsAuthorizationManager type="namespace.webproject.CustomAuthorisationManager,namespace.webproject" />
          </identityConfiguration>
        </system.identityModel>
      

      【讨论】:

      • 感谢您的回复,我尝试清空我的 部分,以便它与上面的内容匹配并将配置移动到代码中,但仍然无法正常工作。我现在也尝试过 IIS 而不是 IIS Express,但这没有用。你也有一个 部分吗?这看起来像什么?
      • 啊,很有趣,所以您需要某种 CustomAuthorisationManager 值才能使用事件将其更改为使用触发事件的“真实”值?
      • 我用它作为授权的中心点,它使它更细化。当我只想通过角色(这是一个声明)进行限制时,我还使用标准 [Authorize] 的组合,但如果我希望 ClaimsAuth 管理器启动,我使用 ThinkTecture 属性或手动调用它,如果我传递的超过缓存声称它。
      猜你喜欢
      • 2013-05-19
      • 2018-04-01
      • 2012-09-17
      • 2020-11-26
      • 2015-11-08
      • 2018-07-09
      • 2016-04-18
      • 2013-01-11
      • 2019-01-27
      相关资源
      最近更新 更多