如何在单个请求上多次调用.ashx [英] How to call .ashx multiple times on a single request

查看:95
本文介绍了如何在单个请求上多次调用.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.

推荐答案

首先你要做的是一个非常糟糕的主意。



原因你的代码不起作用是因为所有RegisterStartupScript都将相关的js添加到输出中,每个脚本都被赋予一个键,因为你的密钥没有改变你要求添加相同的代码块5000次并且作为key没有改变.net什么也没做,因为它已经添加了一个带有该键的块。因此,您需要将密钥更改为



First off what you're doing is a very bad idea.

The reason your code isn't working is because all RegisterStartupScript does is add the relevant js to the output, with each script being given a key as as your key isn't changing you are requesting that the same code block be added 5000 times and as the key isn't changing .net does nothing as it has already added a block with that key. So you'll need to alter the key to something like

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆