我希望将xml文件返回给客户端,然后执行我的逻辑。我尝试使用Response.Flush(),但它在我身上不能正常工作。
我的代码:
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();
}发布于 2014-01-04 01:22:03
Response.End();
通常,在代码中使用Response.End()不是一个好主意。
From the source:提供此方法只是为了与ASP.NET兼容-即与ASP.NET之前的基于COM的网页编程技术兼容。如果要跳转到EndRequest事件并向客户端发送响应,则通常首选调用CompleteRequest。
给定这些信息,而不是这样:
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();执行以下操作:
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 executedhttps://stackoverflow.com/questions/20908330
复制相似问题