[英]asp.net response dual content type
i am sending a large amount of excel content data to the browser using Page.Response.Write("") in a for loop. 我正在for循环中使用Page.Response.Write(“”)将大量的excel内容数据发送到浏览器。
before starting the loop i am changing the conetnt type of the reponse.context property to "ms-excel". 在开始循环之前,我将reponse.context属性的竞争类型更改为“ ms-excel”。
if i have an exception during that for loop , i try to popup an error message to the browser by registering an HTML startup script block and Write it to the browser. 如果在for循环中有异常,我会尝试通过注册HTML启动脚本块并将其写入浏览器来向浏览器弹出错误消息。 before the write i change back the content type to be text/html. 在写之前,我将内容类型改回为text / html。 but i get an error that say that is not possible to change the content type after sending the HTTP Headers. 但我收到一条错误消息,说发送HTTP标头后无法更改内容类型。
How to notify the browser about an error that occured during that for loop? 如何将for循环期间发生的错误通知浏览器? Is it possible to have more that one respone to the same browser tab? 是否可以在同一浏览器选项卡中进行多个响应? by the way,right now i don't want to use ASP.NET AJAX. 顺便说一句,现在我不想使用ASP.NET AJAX。
Did you try Response.ClearHeaders();
您是否尝试过Response.ClearHeaders();
before changing the context type? 在更改上下文类型之前?
If that doesn't work because your Response.Write is causing problems, you might think about going the route of building a string before deciding your content type and then setting the headers. 如果由于Response.Write导致问题而无法解决问题,则可以考虑在确定内容类型然后设置标题之前采用构建字符串的方法。
Page.Response.Write("") will send data to the browser. Page.Response.Write(“”)会将数据发送到浏览器。 When you do that the browser needs to know the type of content it gets in order to render it correct. 当您执行此操作时,浏览器需要知道其获取的内容类型才能正确显示。 If you already told the browser what kind of content you have(and even if you don't, you are already sening data with Response.Write, it will use the default value which I think is text/html) then you can't take it back. 如果您已经告诉浏览器您拥有什么样的内容(即使您没有,即使您已经在使用Response.Write整理数据,它将使用我认为是text / html的默认值),那么您将无法把它收回。 Whatever you are saying to the client is said and you can't take it back. 无论您对客户说的是什么,您都无法收回。 The way to solve your problem is to cache the reply as suggested by Doozer. 解决问题的方法是按照Doozer的建议缓存答复。
/Tibi /提比
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.