问题描述
我有 asp 经典文件,它重定向到下载 excel 文件的 aspx 文件。
但是如果我得到 aspx 的链接并在新标签中打开它,一切正常:
ASP 代码:
Dim NodeIDsCSV : NodeIDsCSV = ""
Dim NodeIDsCSV = Init_PrepareParams()
Dim sharedSecret : sharedSecret = ""
Dim identityAlias : identityAlias = ""
sharedSecret = GetSharedSecret()
identityAlias = GetIdentityAlias()
Response.Redirect "/testCMS/testCMSv2.aspx?NodeIDsCSV=" & NodeIDsCSV & "&SS=" & sharedSecret & "&IdentityAlias=" & identityAlias
ASPX 代码:
string[] nodes = NodeIDsCSV.Split(',');
//Create a stream for the file
Stream stream = null;
//This controls how many bytes to read at a time and send to the client
int bytesToRead = 100000;
// Buffer to read bytes in chunk size specified above
byte[] buffer = new Byte[bytesToRead];
var fileName = "test.xlsx";
// The number of bytes read
try
{
//Create a WebRequest to get the file
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpWebRequest fileReq = (HttpWebRequest) HttpWebRequest.Create("--link--to--service--which-returns-the-file");
fileReq.ProtocolVersion = HttpVersion.Version10;
//Create a response for this request
HttpWebResponse fileResp = (HttpWebResponse) fileReq.GetResponse();
if (fileReq.ContentLength > 0)
fileResp.ContentLength = fileReq.ContentLength;
//Get the Stream returned from the response
stream = fileResp.GetResponseStream();
// prepare the response to the client. resp is the client Response
var resp = HttpContext.Current.Response;
//resp.ClearHeaders();
//Indicate the type of data being sent
resp.ContentType = "application/octet-stream";
//Name the file
resp.Clear();
//resp.Buffer = false;
//resp.BufferOutput = false;
//Apparently this line helps with old version of IE that like to cache stuff no matter how much you tell them!
resp.AddHeader("Pragma","public");
//HttpContext.Current.Response.Write(fileName + "----fileName----");
resp.AddHeader("Content-disposition","attachment; filename=\"" + fileName + "\"");
resp.AddHeader("Content-Length",fileResp.ContentLength.ToString());
resp.AddHeader("Content-transfer-encoding","binary");
int length;
do
{
// Verify that the client is connected.
if (resp.IsClientConnected)
{
// Read data into the buffer.
length = stream.Read(buffer,bytesToRead);
// and write it out to the response's output stream
resp.OutputStream.Write(buffer,length);
// Flush the data
//resp.Flush();
//Clear the buffer
buffer = new Byte[bytesToRead];
}
else
{
// cancel the download if client has disconnected
length = -1;
}
} while (length > 0); //Repeat until no data is read
}
我的问题是什么?你能给我建议一些不同的解决方案吗?
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)