-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
首次访问Status显示:(failed) net::ERR_HTTP2_PROTOCOL_ERROR, 页面也没有正常展示 #2
Comments
ERR_HTTP2_PROTOCOL_ERROR 是一个Chrome浏览器中的错误,表明浏览器在使用HTTP/2协议时遇到了协议违规的情况。这可能是由于服务器发送了不符合HTTP/2标准的响应导致的。 |
我更新到.net 8,没有重现这个问题 |
报错情况只在首次访问页面时出现(首次访问页面:html文件夹中还没有生成该页面的.html/.gzip/.br等缓存文件)。 报错信息:System.InvalidOperationException: Headers are read-only, response has already started. fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] 报错的位置是这一句:context.HttpContext.Response.Headers["Cache-Control"] = "max-age=" + (CurrPageExpireMinutes ?? ExpireMinutes) * 60; |
修改好了,添加了一个判断 if (context.HttpContext.Response.Headers.IsReadOnly == false) {
var fi = new FileInfo(filePath);
var etag = fi.LastWriteTimeUtc.Ticks.ToString();
context.HttpContext.Response.Headers["Cache-Control"] = "max-age=" + (CurrPageExpireMinutes ?? ExpireMinutes) * 60;
context.HttpContext.Response.Headers["Etag"] = etag;
context.HttpContext.Response.Headers["Date"] = DateTime.Now.ToString("r");
context.HttpContext.Response.Headers["Expires"] = DateTime.Now.AddMinutes(CurrPageExpireMinutes ?? ExpireMinutes).ToString("r");
} |
首次访问Status显示:(failed) net::ERR_HTTP2_PROTOCOL_ERROR, 页面也没有正常展示,如图:
The text was updated successfully, but these errors were encountered: