owin – 如何在Startup.cs中添加CamelCasePropertyNamesContract
发布时间:2020-12-15 18:47:51 所属栏目:asp.Net 来源:网络整理
导读:这是我的启动类中的配置方法。 public void Configure(IApplicationBuilder app){ // Setup configuration sources var configuration = new Configuration(); configuration.AddJsonFile("config.json"); configuration.AddEnvironmentVariables(); // Set
这是我的启动类中的配置方法。
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(); }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-3 – 重定向到另一个动作发布动作
- asp.net-mvc – 网格中的kendoui ClientTemplate无法在asp.
- 让OData和NHibernate结合进行动态查询
- asp.net-mvc-4 – ASP.Net MVC JS / CSS捆绑在部署时无法正
- asp.net – 将mvc应用程序发布到Web服务器后无法生成SSPI上
- 写入ASP.NET中的日志文件
- ASP.NET Core 简介 - ASP.NET Core 基础教程 - 简单教程,简
- asp.net – 在PreRender上添加控件页面
- asp.net-mvc – 使用sqlserver express时不创建数据库的Ent
- asp.net core 运用 Redis 配置步骤
推荐文章
站长推荐
热点阅读