【发布时间】:2011-01-03 09:02:15
【问题描述】:
我试图在用户访问页面时强制下载 XML 文件。
这是我正在使用的代码
public partial class GenerateTemplate : LayoutsPageBase
{
protected void Page_Load(object sender, EventArgs e)
{
//.............
//Going about generating my XML
//.............
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=template.xml");
Response.Write(xmlDoc.InnerXml);
Response.Flush();
Response.Close();
}
}
我面临的问题是我的下载窗口无限期挂起,而从未完成文件的下载/打开。
我做错了什么?我不是在这里处理任何对象或关闭任何连接吗?
【问题讨论】: