HTTP标头发送后无法重定向 [英] Cannot redirect after HTTP headers have been sent
问题描述
嗨先生,
我收到错误在发送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");
推荐答案
您无法为一个请求发送两个响应。在这里你有两个。删除行
You cannot send send two response for one request. And here you have two. Remove the lines
Response.Flush();
Response.Close();
并尝试
and try
我必须从上面的两行中删除哪一行。
Hi,
What line i have to remove from the above two lines.
这篇关于HTTP标头发送后无法重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!