asp.Net   发布时间:2022-04-07  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了owin – 如何在Startup.cs中添加CamelCasePropertyNamesContractResolver?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的启动类中的配置方法。
public void Configure(IApplicationBuilder app)
{
    // Setup configuration sources
    var configuration = new Configuration();
    configuration.AddJsonFile("config.json");
    configuration.AddEnvironmentVariables();

    // Set up application services
    app.Useservices(services =>
    {
        // Add EF services to the services container
        services.AddEntityFramework()
           .AddSqlServer();

        // Configure DbContext
        services.SetupOptions<DbContextOptions>(options =>
        {
           optionS.UseSqlServer(configuration.Get("Data:DefaultConnection:ConnectionString"));
        });

        // Add Identity services to the services container
        services.AddIdentitySqlServer<ApplicationDbContext,ApplicationUser>()
           .AddAuthentication();

        // Add MVC services to the services container
        services.AddMvc();
    });

    // Enable Browser Link support
    app.UseBrowserLink();

    // Add static files to the request pipeline
    app.UseStaticFiles();

    // Add cookie-based authentication to the request pipeline
    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        Authenticationtype = claimsIdentityOptions.DefaultAuthenticationType,LoginPath = new PathString("/Account/Login"),});

    // Add MVC to the request pipeline
    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",template: "{Controller}/{action}/{id?}",defaults: new { controller = "Home",action = "Index" });

        routes.MapRoute(
            name: "api",template: "{Controller}/{id?}");
    });
}

在哪里可以访问httpConfiguration实例,以便我可以设置CamelCasePropertyNamesContractResolver,就像我在WebApi 2中所做的那样:

var formatterSetTings = config.Formatters.JsonFormatter.serializerSetTings;
formatterSetTings.FormatTing = FormatTing.None;
formatterSetTings.ContractResolver = new CamelCasePropertyNamesContractResolver();

解决方法

配置功能已从Beta 6或7中的services.AddMvc()中删除。对于Beta 7,在Startup.cs中,将以下内容添加到Configureservices函数中:
services.AddMvc().AddJsonOptions(options =>
{
    options.serializerSetTings.ContractResolver = 
        new CamelCasePropertyNamesContractResolver();
});

大佬总结

以上是大佬教程为你收集整理的owin – 如何在Startup.cs中添加CamelCasePropertyNamesContractResolver?全部内容,希望文章能够帮你解决owin – 如何在Startup.cs中添加CamelCasePropertyNamesContractResolver?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。