问题描述
嗨先生,
我收到错误在发送HTTP标头后无法重定向
,同时在下载操作后重定向到另一个页面。
我分享了代码供您参考。请给我这个问题的解决方案。
Default.aspx.cs:
*********************
Response.Clear();
Response.ContentType =application / pdf;
string filePath =d:\\+ filename +。pdf ;
Response.AddHeader(Content-Disposition,String.Format(attachment; filename = \{0} \,filePath));
Response.OutputStream.Write(bytes,0,bytes.Length);
Response.Buffer = true;
Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.Flush();
Response.Close();
Response.Redirect(StudentHome.aspx);
Hi sir,
I am getting the error "Cannot redirect after HTTP headers have been sent"
while redirecting to another page after the download operation.
I shared the code for your reference. Kindly give me the solution for this problem.
Default.aspx.cs:
*********************
Response.Clear();
Response.ContentType = "application/pdf";
string filePath = "d:\\" + filename + ".pdf";
Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", filePath));
Response.OutputStream.Write(bytes, 0, bytes.Length);
Response.Buffer = true;
Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.Flush();
Response.Close();
Response.Redirect("StudentHome.aspx");
推荐答案
Response.Flush();
Response.Close();
并尝试
and try
这篇关于HTTP标头发送后无法重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!