本文介绍了如何在单个请求上多次调用.ashx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在努力将图像作为以二进制格式保存在数据库中的jpg下载。为此我打电话给.ashx文件下载并将图像保存到我的电脑。



我尝试过:



要从.aspx文件中调用.ashx,我写了以下代码。

protected void btn_Click(object sender,EventArgs e)

{

BLL.Certificate objBCert = new BLL.Certificate();

DataSet dsListData = new DataSet();

dsListData = objBCert .FuntoFillListData();

if(dsListData!= null)

{

for(int i = 0; i< dsListData.Tables [0] .Rows.Count; i ++)

{



string script = string.Format(window.open('{0 }');,http:// localhost:9501 / MyApp / ShowImage.ashx?id =+ dsListData.Tables [0] .Rows [i] [id]。ToString());



//在新标签页中打开浏览器

Page.ClientScript.RegisterStartupScript(this.GetType(),newPage+ UniqueID,script,true);



//关闭浏览器选项卡

ClientScript.RegisterStartupScript(typeof(Page),closePage,window.close() ;,真实);

}

}

}



我有大约5000条记录,所以我需要在一次请求中从.aspx调用5000次的.ashx文件。



以上,代码首先可以下载并保存一个但是,上面的循环不会多次调用.ashx文件。所以,我无法下载多张图片。



请帮帮我。



谢谢你预期。

Hi All,

I am working on "Downloading the image as a jpg saved in database as a binary format". For that I have called .ashx file to download and save the image to my computer.

What I have tried:

To call .ashx from .aspx file I have written below code.
protected void btn_Click(object sender, EventArgs e)
{
BLL.Certificate objBCert = new BLL.Certificate();
DataSet dsListData = new DataSet();
dsListData = objBCert.FuntoFillListData();
if (dsListData != null)
{
for (int i = 0; i < dsListData.Tables[0].Rows.Count; i++)
{

string script = string.Format("window.open('{0}');", "http://localhost:9501/MyApp/ShowImage.ashx?id=" + dsListData.Tables[0].Rows[i]["id"].ToString());

//To open the browser in new tab
Page.ClientScript.RegisterStartupScript(this.GetType(), "newPage" + UniqueID, script, true);

//To close the browser tab
ClientScript.RegisterStartupScript(typeof(Page), "closePage", "window.close();", true);
}
}
}

I have around 5000 records, so I need to call 5000 times the .ashx file from .aspx on a single request.

Above, code first fine for downloading and saving one image, but, the loop above doesn't call .ashx file multiple times. So, I can't download more than one image.

Please help me.

Thanks for anticipation.

推荐答案

Page.ClientScript.RegisterStartupScript(this.GetType(), "newPage" + UniqueID + i.ToString(), script, true); 





这样做会将5000个window.open语句添加到输出html并使浏览器崩溃并惹恼用户。如果你解释它是什么,你最终会尝试做某人可能有更好的建议。



What that will do is add 5000 window.open statements to the output html and crash the browser and annoy your users. If you explain what it is you're ultimately trying to do someone might have a better suggestion.


这篇关于如何在单个请求上多次调用.ashx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 06:09