开发者

Unwanted output when using Response.Flush()

开发者 https://www.devze.com 2023-03-19 05:28 出处:网络
I have an asp.net (.aspx) page containing a button. When I click that button I wish for some content (given as a byte array and created in my code-behind) to be written into a text

I have an asp.net (.aspx) page containing a button. When I click that button I wish for some content (given as a byte array and created in my code-behind) to be written into a text file and downloaded to the user (Open\Save..). I use the following but开发者_如何转开发ton click handler syntax:

  Response.Buffer = true;
            Response.Charset = "";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = "text/plain";
            Response.AddHeader("content-disposition", "attachment;filename=" + "non-queries.txt");
            Response.BinaryWrite(\*Here I send the byte array*\);
            Response.Flush();

Now the content of the byte array does get written into the file, but what also gets written is the html content of the aspx page containing the button, which I don't want written.

Can you help? Where do I go wrong?


Adding Response.End() should do the trick. I had a similar problem and this resolved the issue for me. See the following post.


You should try adding Response.Clear(); at the top and see if that solves your problem. You can also add Response.ClearContent();.

0

精彩评论

暂无评论...
验证码 换一张
取 消