Ole*_*ers 0 asp.net httpresponse
我得到了一个"普通"的ascx-Page,其中包含HTML-Parts以及后面的代码.这些元素都应该在正常条件下显示(工作).
现在我希望能够设置一个request-parameter,这会导致页面zu以不同方式呈现.然后,它发送该页面上的信息,不是人类可读的,而是机器:
string jsonProperty = Request["JSonProperty"];
if (!string.IsNullOrEmpty(jsonProperty))
{
Response.Clear();
Response.Write(RenderJSon());
// Response.Close();
return;
Run Code Online (Sandbox Code Playgroud)
此代码位于Page_PreRender内.现在我的问题是:字符串被正确发送到浏览器,但之后仍然呈现"标准"html内容.
当我删除"Response.Close();" 评论我收到"ERR_INVALID_RESPONSE"
有什么线索如何在不创建额外页面的情况下解决这个问题?
我可以建议Response.End()可以抛出错误.
使用Response.SuppressContent = true; 停止进一步处理"标准"html
string jsonProperty = Request["JSonProperty"];
if (!string.IsNullOrEmpty(jsonProperty))
{
Response.Clear();
Response.ContentType = "application/json";
Response.Write(RenderJSon());
Response.Flush(); // Flush the data to browser
Response.SuppressContent = true; // Suppress further output - "standard" html-
// content is not rendered after this
return;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3387 次 |
| 最近记录: |