网站打开慢 可以只换空间不换域名吗,wordpress 微信授权,做视频网站用什么系统,网站小图标 免费点击上方蓝字关注“汪宇杰博客”导语昨天刚发了一篇《生产大爆炸发生问题的是已经被删除的博客文章#xff0c;正常情况下#xff0c;这些不存在的文章会直接显示自定义的404页面#xff0c;但实际上产生了500异常。日志如下#xff1a;2019-09-26 00:11:50.8405|RD00155DB… 点击上方蓝字关注“汪宇杰博客”导语昨天刚发了一篇《生产大爆炸发生问题的是已经被删除的博客文章正常情况下这些不存在的文章会直接显示自定义的404页面但实际上产生了500异常。日志如下2019-09-26 00:11:50.8405|RD00155DB89A5B|WARN|Moonglade.Web.Controllers.PostController|Post not found, parameter 2014/7/23/my-surface-pro-3-review-system-software.,GET https://edi.wang/post/2014/7/23/my-surface-pro-3-review-system-software,Slug,66.249.71.1352019-09-26 00:11:51.1174|RD00155DB89A5B|WARN|Moonglade.Web.Controllers.PostController|Post not found, parameter 2014/7/23/my-surface-pro-3-review-system-software.,GET https://edi.wang/error,Slug,66.249.71.1352019-09-26 00:11:51.1174|RD00155DB89A5B|ERROR|Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware|An unhandled exception has occurred while executing the request.,System.ArgumentException: An item with the same key has already been added. Key: x-pingback at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value) at Microsoft.AspNetCore.HttpSys.Internal.HeaderCollection.Add(String key, StringValues value)看上去像是个Pingback HTTP头被重复添加的问题。但实际上这个头被添加产生异常的本质原因是请求博客文章的Slug这个Action被执行了两次。重现故障这个问题在开发时并没有发现staging环境可以重现但由于偷懒没测过exception pathhappy path过了就发布了。之所以开发环境 works on my machine 是因为这样一个设定大部分 ASP.NET Core 程序都会这么做毕竟是默认模板里的实践if (env.IsDevelopment()){ ListAllRegisteredServices(app); app.UseDeveloperExceptionPage();}else{ app.UseExceptionHandler(/error); app.UseStatusCodePagesWithReExecute(/error, ?statusCode{0});}出问题的是 UseStatusCodePagesWithReExecute() 这个中间件。最终在 GitHub 上找到了一个已知问题https://github.com/aspnet/AspNetCore/issues/13715我用 VS2019 16.3.1 .NET Core 3.0 正式版建了个测试工程重现了这个问题。public IActionResult Index(int id 0){ if (id 1) { return NotFound(); } return View();}[Route(/error)][ResponseCache(Duration 0, Location ResponseCacheLocation.None, NoStore true)]public IActionResult Error(int? statusCode null){ return Content($Test Error Action: {statusCode});}public void Configure(IApplicationBuilder app, IWebHostEnvironment env){ //app.UseStatusCodePages(); //app.UseExceptionHandler(/error); app.UseStatusCodePagesWithReExecute(/error, ?statusCode{0}); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints { endpoints.MapControllerRoute( name: default, pattern: {controllerHome}/{actionIndex}/{id?}); });}访问 /Home/Index?id1id1的请求成功执行到 NotFound(); 正常情况应该立即执行 /error?statusCode404当实际上 Error 这个 Action 根本没有跑进去而是马上再次执行了 Indexid0而因为执行的逻辑是ReExecute也就是把action的执行结果放到“父”action里输出所以会触发两次pingback头的添加导致我博客大爆炸。复制粘贴 能跑就行微软并不打算在 3.0 的补丁更新中修复这个问题而是直接放到了 3.1。好在微软提供了 workaround所以我们只能先忍几个月。在 UseRouting() 和 UseStatusCodePagesWithReExecute() 之间加入一段神奇的代码即可结束福爆。app.UseStatusCodePagesWithReExecute(/error, ?statusCode{0});// Workaround .NET Core 3.0 known bug// https://github.com/aspnet/AspNetCore/issues/13715app.Use((context, next) { context.SetEndpoint(null); return next();});实在不行 删库跑路 也挺省心目前 .NET Core 3.0 升级问题多多资料少少一不小心就容易领取福报。如果追求刺激和拥抱开源的乐趣可以像我或者博客园一样直接踩坑。如果追求稳定不想被公司开除建议等 3.1 再更新吧~ 毕竟微软拥抱开源以后的产品.1 才是能用的早上更新的 VS2019 16.3.1笑而不语。