开发者

ASP.NET Response Content

I have tested this in IIS 6.1, IE 7, ASP.NET 3.5 SP1.

I have a file download in a method in my aspx codebehind:

Response.ContentType = contentType;
Response.AppendHeader("Content-Disposition", contentDisposition);
Response.BinaryWrite(file);

This works great, but if I attempt to modify any of my sever side controls the changes do not take affect. I have isolated this down to the call to ContentType, this apparently whipes all pending changes to the Response stream when called? Does this sound familiar to anyone?

If the code takes an alternate branch and the call to download does not fire the markup is modified as expected.

Any suggestions on how I can fix this and have the page flush the attachment and update the UI in the same response stream?

This is specifically for updating the ValidationSummary, so I could tear into 开发者_运维知识库the JS on the PageRequestManager event complete as a last resort, but I'd prefer not to rely on JS for this.


Not sure what you're trying to do - are you trying to simultaneously serve a download file and an update to the HTML page they linked to it from? That's not how HTML works.

If you want to achieve this result then you'll basically have to render a meta redirect that goes to the file which is returned in the HTML, that way the page will load and then the download starts (Like you'll see on a lot of download sites).


As fyjham said, I don't really understand what you're trying to do. A few tips that might help:

  1. Keep in mind that the Render phase, when the content from your markup and controls is generated, happens as almost the very last phase in your code behind (well after Page_Load)
  2. Once you flush headers, you can't set them again
  3. Controls can override some HTTP headers
  4. You can't mix a file download and HTML markup in the same HTTP response
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜