[英]Why asp.net dropdownlist selectedvalue is not set during postback
[英]Why my files get redownloaded on postback in asp.net?
嗨,我正在使用以下處理程序在asp.net Web應用程序上提供文件下載:
public void ProcessRequest(HttpContext context)
{
using (SFTDBEntities db = new SFTDBEntities())
{
try
{
string Id = context.Request.QueryString["Id"];
Guid Id_LogServerLogFilesData = Guid.Parse(Id);
LogServerLogFile logServerLogFile = new LogServerLogFile();
logServerLogFile = db.LogServerLogFiles.FirstOrDefault(x => x.Id == Id_LogServerLogFilesData);
byte[] data = logServerLogFile.LogServerLogFilesData.TFFileData.ToArray();
context.Response.Buffer = false;
context.Response.ContentType = logServerLogFile.TFFileMimeType;
int len = data.Length, bytes;
context.Response.AppendHeader("content-length", len.ToString());
context.Response.AddHeader("content-disposition", "attachment;filename=" + logServerLogFile.TFFileName);
byte[] buffer = new byte[1024];
Stream outStream = context.Response.OutputStream;
using (Stream stream = new MemoryStream(data))
{
while (len > 0 && (bytes =
stream.Read(buffer, 0, buffer.Length)) > 0)
{
outStream.Write(buffer, 0, bytes);
len -= bytes;
}
}
context.Response.Flush();
context.Response.End();
}
catch { }
}
}
當我單擊gridview中的超鏈接以下載文件時:
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btn" runat="server" Text="download" PostBackUrl='<%#Eval("DownloadPath") %>' Visible='<%#Eval("TFIsDownloadable") %>' Style="text-decoration: none"></asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="40px" />
</asp:TemplateField>
文件下載成功1
但是問題是,如果我執行回發(在頁面上單擊網格或單擊搜索按鈕),則在下載文件后,文件將自動重新下載!
任何幫助將不勝感激。
我建議使用Fiddler或類似工具檢查您的請求。
存在類似的問題,這是由於請求參數持續存在到后續回發中引起的。 (即Form .__ EVENTTARGET.value不變)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.