作者kyo0010 (~KYO~)
看板C_Sharp
标题[问题] ashx下载疑问
时间Fri Mar 25 12:07:04 2016
先附上下载语法
private void DownLoadFile(string parFilePath, string fileName)
{
string pathStr = @"D:\web测试\html\下载\option\test.jpg";
string FilePath = pathStr;
try
{
FileStream fr = new FileStream(FilePath, FileMode.Open);
Byte[] buf = new Byte[fr.Length];
fr.Read(buf, 0, Convert.ToInt32(fr.Length));
fr.Close();
fr.Dispose();
context.Response.Clear();
context.Response.ClearHeaders();
context.Response.Buffer = true;
context.Response.AddHeader("content-disposition",
"attachment; filename=" + fileName);
context.Response.BinaryWrite(buf);
context.Response.End();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
此段语法在在一般的aspx可以成功下载
但用在html+ajax之後点了会没反应
catch会出现
"{无法评估运算式,因为程式码已经最佳化,或者原生框架不在呼叫堆叠的最上层。}
爬一天文 能加的header也加到有点乱了
所以贴上的是还原後 最原先aspx能执行的语法
现在还是无解 求神人大大指引一条明路
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 59.120.119.244
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_Sharp/M.1458878827.A.419.html
1F:→ Litfal: 你有跨网站吗? 03/25 23:09
没有跨 在同一个专案目录下 用$.post有呼叫到ashx
※ 编辑: kyo0010 (39.12.2.53), 03/27/2016 20:41:07
2F:推 Ammenze: 不要用ajax,直接设定连结的url到你的ashx就好 03/28 14:08