且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将Content-Length,Content-Type和Last-Modified添加到HTTP响应消息头

更新时间:2022-06-07 03:44:23

内容类型应该是使用现有属性设置,如下例所示:

The "content type" should be set by using the existing property like in the next example:
httpResponse.ContentType = "application/vnd.ms-excel";





其他标题如添加文件下载应该与您的示例类似:



Other header like adding a file to download should be like in your example:

httpResponse.AddHeader("content-disposition", "attachment; filename=" + this.FileDownloadName);





你的对象httpResponse应该在后面的ASPX代码中使用,如下一个例子所示:



And your object httpResponse should be used from your ASPX code behind, like in the next example:

HttpResponse httpResponse = HttpContext.Current.Response;


我找到了我们可以添加的解决方案



I have find the solution we can add like this

httpResponse.Content.Headers.ContentType = new MediaTypeHeaderValue(item.ContentType);
                  httpResponse.Content.Headers.ContentLength = item.Size;
                  var info = TimeZoneInfo.FindSystemTimeZoneById("UTC");
                  httpResponse.Content.Headers.LastModified = TimeZoneInfo.ConvertTime(item.LastModifiedDate, info);