Asp.net core 学习笔记 2.1 升级到 2.2
首先跟着官网 step by step
https://docs.microsoft.com/en-us/aspnet/core/migration/21-to-22?view=aspnetcore-2.2&tabs=visual-studio
Bug 1
发现一个 odata routing issue
https://github.com/Microsoft/aspnet-api-versioning/issues/361
因为 2.2 router 有升级, 貌似 odata 没有跟上.
https://blogs.msdn.microsoft.com/webdev/2018/08/27/asp-net-core-2-2-0-preview1-endpoint-routing/
目前只好先关上它
options.EnableEndpointRouting = false;
然后继续追踪
https://github.com/OData/WebApi/issues/1707
Bug 2
https://github.com/aspnet/AspNetCore/issues/6166
在做 webapi 又跨域的情况下, 游览器会发送 option request , 然而因为 2.2 有对 http2 之类的升级, 好像导致了 iis 的返回有点问题.
具体原因我就不管了. 反正就是用 work around 顶一顶先.
app.Use(async (ctx, next) => { await next(); if (ctx.Response.StatusCode == 204) { ctx.Response.ContentLength = 0; } });
持续追踪 https://github.com/aspnet/AspNetCore/issues/4398
Bug 3
serilog-extensions-logging-file 好像不能用了...虽然这东西本来就没有维护了.
那就找替代吧.
https://andrewlock.net/creating-a-rolling-file-logging-provider-for-asp-net-core-2-0/
https://nblumhardt.com/2017/08/use-serilog/
https://github.com/serilog/serilog-settings-configuration
https://stackoverflow.com/questions/40880261/configuring-serilog-rollingfile-with-appsettings-json
https://nblumhardt.com/2016/03/reading-logger-configuration-from-appsettings-json/
https://github.com/serilog/serilog-aspnetcore
https://github.com/serilog/serilog-sinks-file
appsetting.json
"Serilog": { "MinimumLevel": { "Default": "Information", "Override": { "Microsoft": "Information", "System": "Warning", "Hangfire": "Warning" } }, "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], "WriteTo": [ { "Name": "Console" }, { "Name": "File", "Args": { "path": "Log/log.txt", "rollingInterval": 3 } } ] },
main.cs
public static void Main(string[] args) { CurrentDirectoryHelpers.SetCurrentDirectory(); var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true) .AddEnvironmentVariables() .Build(); Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(configuration) .CreateLogger(); WebHost.CreateDefaultBuilder(args) .UseUrls("http://192.168.1.152:61547") .ConfigureSecretFromCloud(skipInDevelopmentMode: true) .UseSerilog() .UseStartup<Startup>().Build().Run(); }
替代方案很简单. 但是 2.2 有 bug !
https://github.com/aspnet/AspNetCore/issues/4206
因为 serilog 是在 main.cs 去获取 appsetting.json 然后 setup config 的. 而 2.2 iis 情况下有一个叫 In-Progress 的鬼.
它会把 path 给弄不清楚. 幸好微软团队及时给了 work around 参考上面的 gitHub, 对话下方就有 word around 了.
相关文章
- ASP.NET Core Identity自定义数据库结构和完全使用Dapper而非EntityFramework Core
- ASP.NET Core MVC上传、导入、导出知多少
- 使用 ASP.NET Core MVC 创建 Web API(六)
- 学习ASP.NET Core Razor 编程系列十七——分组
- 学习ASP.NET Core Razor 编程系列十六——排序
- Learn asp.net core blazor project with ChatGPT
- ASP.NET Session State Overview
- ASP.NET MVC WebApi 返回数据类型序列化控制(json,xml) 用javascript在客户端删除某一个cookie键值对 input点击链接另一个页面,各种操作。 C# 往线程里传参数的方法总结 TCP/IP 协议 用C#+Selenium+ChromeDriver 生成我的咕咚跑步路线地图 (转)值得学习百度开源70+项目
- C# MVC 用户登录状态判断 【C#】list 去重(转载) js 日期格式转换(转载) C#日期转换(转载) Nullable<System.DateTime>日期格式转换 (转载) Asp.Net MVC中Action跳转(转载)
- C# asp.net webapi下支持文件下载输出接口
- 关于Asp.net超时,延长读取sql server数据库的超时时间!(已解决)
- Asp.Net中替换JSON中主键内容的函数(很简单,示例+说明)
- 在ASP.NET MVC中实现Select多选
- ASP.NET Web API实践系列02,在MVC4下的一个实例, 包含EF Code First,依赖注入, Bootstrap等
- ASP.NET Core 2.0 Web API项目升级到ASP.NET Core 3.0概要笔记
- ASP.NET Core Web API下事件驱动型架构的实现(三):基于RabbitMQ的事件总线
- 在docker中运行ASP.NET Core Web API应用程序
- ASP.NET Web API涉及到的上下文
- 在服务器 部署 asp.net core 报502.5的错
- 使 Asp.net Core Hosting Bundle 立即生效
- asp.net Core依赖注入汇总
- ASP.NET Core 中的 Request Feature
- Asp.net web form 动态生成控件的注意事项
- ASP.Net WebForm温故知新学习笔记:一、aspx与服务器控件探秘
- ASP.NET Web Pages - 添加 Razor 代码
- uniapp跨域调用ASP.NET Core Web API