【asp.net core】asp.net中Server.Transfer重定向到图片导致缓存机制失效解决方法

更新时间:2019-07-11    来源:J2EE/EJB/服务器    手机版     字体:

【www.bbyears.com--J2EE/EJB/服务器】

例如,直接请求图片时服务器响应的HTTP头如下:

引用内容
HTTP/1.1 200 OK
Content-Length: 48150
Content-Type: image/jpeg
Last-Modified: Tue, 18 Dec 2012 15:01:50 GMT
Accept-Ranges: bytes
ETag: "e119ee9b30ddcd1:1c48"
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Sat, 06 Sep 2014 08:07:17 GMT

使用Server.Transfer重定向到图片:


<% Server.Transfer("/test.jpg") %>

服务器响应的HTTP头如下:

引用内容
HTTP/1.1 200 OK
Date: Sat, 06 Sep 2014 08:08:23 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Content-Length: 48150
Content-Type: text/html
Set-Cookie: ASPSESSIONIDCABATASQ=HCKPNPPAECAKPBJJNHOENINF; path=/
Cache-control: private

存在问题

·不能正确返回Content-Type的值image/jpeg;
·HTTP头缺少了Last-Modified和ETag,致使缓存机制失效;

这是Server.Transfer设计使然,应当无解。ASP.NET可以使用RewritePath代替它实现服务器端重定向。

本文来源:http://www.bbyears.com/jsp/57450.html