Search code examples
securityenterprise-library

Enterprise Library Security Block


Does anyone know if there is a way to create the security configuration section via the Enterprise Library API or do we have to use the config wizard / edit by hand?


Solution

  • Yes, you can configure any section via the new fluent interface. Just use ConfigurationSourceBuilder. Like so:

    var builder = new ConfigurationSourceBuilder();
    
    builder.ConfigureSecurity()
           .AuthorizeUsingRuleProviderNamed("MyRules")
             .SpecifyRule("Rule1", "MyRuleExpression")
           .CacheSecurityInCacheStoreNamed("SecCache")
             .WithOptions
               .UseSharedCacheManager("MyCacheManager")
               .SetAsDefault();
    
    var configSource = new DictionaryConfigurationSource();
    builder.UpdateConfigurationWithReplace(configSource);
    EnterpriseLibraryContainer.Current 
      = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
    

    You even get IntelliSense support.

    More info on MSDN