【发布时间】:2011-05-30 04:26:57
【问题描述】:
使用下面的代码我无法显示打开/另存为文件对话框:
public void ProcessRequest(HttpContext context)
{
string link = context.Request.QueryString["Link"];
string extension = Path.GetExtension(link);
string fileName = Path.GetFileName(link);
string fullPath =
String.Format("{0}\\{1}",
context.Server.MapPath("~/Content/Uploads/"),
fileName);
if (File.Exists(fullPath))
{
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.AddHeader(
"Content-Length",
new FileInfo(fullPath).Length.ToString());
string contentType;
switch (extension)
{
default:
contentType = "application/octet-stream";
break;
}
context.Response.ContentType = contentType;
context.Response.AddHeader(
"Content-Disposition",
String.Format("attachment; filename={0}", fileName));
context.Response.WriteFile(fullPath, true);
context.Response.Flush();
}
}
我尝试关闭回复,让回复保持打开状态,使用TrasmitFile(),但我从未收到任何对话或任何反馈。我也尝试过调试它,但没有抛出异常。在 IE 7/8 和 Chrome 中尝试过。任何帮助表示赞赏。
谢谢!
下面是 Fiddler 的输出:
HTTP/1.1 200 OK 缓存控制:私有 内容长度:3813 内容类型: 应用程序/八位字节流服务器: Microsoft-IIS/7.5 内容处置: 附件; 文件名=b1af9b34-28cc-4479-a056-8c55b41a5ece.txt X-AspNet-版本:4.0.30319 X-Powered-By:ASP.NET 日期:星期四,23 格林威治标准时间 2010 年 12 月 21:51:58
* Home * Hotels * Reviews * Community * Travel Guide * Travel Insurance * Contact us* FIDDLER:RawDisplay 被截断为 128 个字符。右击禁用 截断。 *
【问题讨论】:
-
Fiddler 对 http 连接有什么看法?
-
您认为 Fiddler 的哪些信息需要粘贴?
-
否决票的解释如何...
-
如果它让您感觉更好,我对您的问题投了 up 票,因为我想用尽可能多的脚本语言跟踪解决这个特定问题。 ;-)
标签: c# asp.net jquery .net-4.0 iis-6