小编erw*_*ard的帖子

无法在Startup.cs中保存ConfigurationSection - Web API

我无法在启动时将我的自定义保存ConfigurationSection在我的web.config文件中.

我已经按照本教程进行了通用实现.我的单元测试通过了,我能够ConfigurationSection在单元测试中保存de !

在应用程序启动时,我想ClaimCollection基于控制器类名和所属方法名建立一个:

Startup.cs

public void Configuration(IAppBuilder app)
{

    Config = new HttpConfiguration();

    BuildUnityContainer();

    BuildClaimCollection(); <----------------

    ConfigureOAuth(app);

    WebApiConfig.Register(Config);
    app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
    app.UseWebApi(Config);

}

public void BuildClaimCollection()
{

    //config section
    MethodClaimSection methodClaimSection = BaseConfigurationSection<MethodClaimSection>.Open();

    var methods = GetClaimAuthorizedMethods();

    foreach (var method in methods)
    {
        var claimValue = GetClaimValueFromMethodName(method);
        var claim = new MethodClaimElement()
        {
            Type = "Method",
            Value = claimValue
        };

        methodClaimSection.MethodClaims.Add(claim);
    }
    methodClaimSection.Save();
}  
Run Code Online (Sandbox Code Playgroud)

BaseConfigurationSection.cs

public abstract class BaseConfigurationSection<T> : ConfigurationSection …
Run Code Online (Sandbox Code Playgroud)

c# configurationsection asp.net-web-api

5
推荐指数
0
解决办法
701
查看次数

标签 统计

asp.net-web-api ×1

c# ×1

configurationsection ×1