首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在asp.net中刷新xml文件?

问如何在asp.net中刷新xml文件?
EN

Stack Overflow用户
提问于 2014-01-04 00:33:21
回答 1查看 183关注 0票数 0

我希望将xml文件返回给客户端,然后执行我的逻辑。我尝试使用Response.Flush(),但它在我身上不能正常工作。

我的代码:

代码语言:javascript
复制
protected void Page_Load(object sender, EventArgs e)
{
string arg1= this.Request["arg1"];
string arg2= this.Request["arg2"];
string arg3= this.Request["arg3"];

var doc = new XmlDocument();
XmlNode responseNode = doc.CreateElement("response");
doc.AppendChild(responseNode);

var messageNode = responseNode.AppendChild(doc.CreateElement("message"));
messageNode.InnerText = "Your request is being processed";

Response.Clear();
Response.ContentType = "text/xml"; 
Response.ContentEncoding = System.Text.Encoding.UTF8;
doc.Save(Response.Output);
Response.Flush(); // I want to display xml in this moment but it doesn't work

LogicManager manager = new LogicManager();
manager.DoSth(arg1, arg2, arg3);

Response.End();
}
EN

回答 1

Stack Overflow用户

发布于 2014-01-04 01:22:03

Response.End();

通常,在代码中使用Response.End()不是一个好主意。

From the source:提供此方法只是为了与ASP.NET兼容-即与ASP.NET之前的基于COM的网页编程技术兼容。如果要跳转到EndRequest事件并向客户端发送响应,则通常首选调用CompleteRequest。

给定这些信息,而不是这样:

代码语言:javascript
复制
Response.Flush(); // I want to display xml in this moment but it doesn't work

LogicManager manager = new LogicManager();
manager.DoSth(arg1, arg2, arg3);

Response.End();

执行以下操作:

代码语言:javascript
复制
Response.Flush(); // I want to display xml in this moment but it doesn't work
Response.CompleteRequest();

LogicManager manager = new LogicManager();
manager.DoSth(arg1, arg2, arg3);
// here you might want to make sure that no other page handlers are executed
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20908330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档