owin – 如何在Startup.cs中添加CamelCasePropertyNamesContractResolve
发布时间:2020-05-23 11:39:37 所属栏目:asp.Net 来源:互联网
导读:这是我的启动类中的配置方法。 public void Configure(IApplicationBuilder app){ // Setup configuration sources var configuration = new Configuration(); configuration.AddJsonFile(config.json); config
|
这是我的启动类中的配置方法。 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 – ASP.NET MVC从数据库加载Razor视图
- ASP.NET MVC 4 JSON绑定到视图模型 – 嵌套对象错误
- asp.net-mvc – Razor查看引擎在VB.NET中的怪癖
- asp.net-mvc – EF 4代码如何首先处理生产环境中的模式更改
- asp.net-mvc – DefaultModelBinder不绑定嵌套模型
- asp.net-mvc-3 – MVC3中的模型级错误?
- asp.net 分页显示数据表的数据的代码
- asp.net-mvc-3 – “区域”文件夹中的样式,脚本和图像
- dependency-injection – Ninject:构造函数参数
- 如何在ASP.NET中使用列表集合作为Repeater数据源与C#
推荐文章
站长推荐
- asp.net-mvc – MiniProfiler与EF“模型第一”ed
- 如何在ASP.NET中动态生成列表项到无序列表?
- asp.net – 在我的网站中添加HttpModule时出现“
- asp.net-mvc-4 – 使用WebApi和外部登录的ASP.NE
- asp.net – Reflection构成了什么风险? (中等信
- asp.net – 如何在Firefox上命名文件以供下载?
- asp.net-mvc – 如何将用户重定向到ASP.NET MVC中
- asp.net-mvc – 向RouteValueDictionary添加复杂
- ASP.NET MVC 3使用身份验证
- asp.net-mvc-4 – 如何在MVC 4中创建自定义WebSe
热点阅读
