我有一个 Blazor Server 应用程序(使用 .NET 5 创建,但问题不会随 .NET 6 改变),我想在其中使用 ETag 来管理下载。Firefox 在请求标头中发送正确的 If-None-Match 条目,但在我的 Blazor Server 应用程序中看不到 If-None-Match 条目。
由于我不确定问题出在浏览器端 (Firefox) 还是 Blazor,我安装了 Wireshark 以查看网络上的真实请求。Wireshark 告诉我,If-None-Match 确实包含在请求中。
这是我使用 Wireshark 捕获的 Get 请求:
Frame 5058: 1170 bytes on wire (9360 bits), 1170 bytes captured (9360 bits) on interface \Device\NPF_Loopback, id 0
Null/Loopback
Internet Protocol Version 4, Src: 127.0.0.1, Dst: 127.0.0.1
Transmission Control Protocol, Src Port: 64501, Dst Port: 5000, Seq: 7453, Ack: 800269, Len: 1126
Hypertext Transfer Protocol
GET /download/4 HTTP/1.1\r\n
[Expert Info (Chat/Sequence): GET /download/4 HTTP/1.1\r\n]
Request Method: GET
Request URI: /download/4
Request Version: HTTP/1.1
Host: localhost:5000\r\n
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0\r\n
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8\r\n
Accept-Language: en-US,en;q=0.5\r\n
Accept-Encoding: gzip, deflate\r\n
Connection: keep-alive\r\n
Referer: http://localhost:5000/index\r\n
[truncated]Cookie: .AspNetCore.Cookies=CfDJ8EutmVsi1DJClRRRhnZzvClYqVk3pTmt9Hskag9bq46cX4NeK_HW8JZX2-cW5bDj3TZBQPyOg5a5j52315xYztq-jPwZc4wqWrJjS2dS0XNN5HJWM4L8-TainK1_-vdNLNippCYvf
Upgrade-Insecure-Requests: 1\r\n
Sec-Fetch-Dest: iframe\r\n
Sec-Fetch-Mode: navigate\r\n
Sec-Fetch-Site: same-origin\r\n
If-None-Match: Lijl+WLFyaFjntRkRRw5Bw==\r\n
\r\n
[Full request URI: http://localhost:5000/download/4]
[HTTP request 8/8]
[Prev request in frame: 4543]
这就是我在 Blazor Server 的调试器中看到的:
我设置断点的中间件位于处理链的最开始:
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseMyMiddleware(); <- Here is where we see the request headers in the above image.
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
所以它是 .NET 5 Blazor Server 中的第一个中间件Startup.cs
。
你有什么想法,为什么我没有看到 If-None-Match 条目?顺便说一句,它与 Kestrel 服务器一起运行,但使用“IIS Express”是一样的。