ASP.Net Response.Close问题问题、Net、ASP、Close

由网友(恶魔祖宗)分享简介:我使用ASP.Net +净3.5 + VSTS 2008 + IIS 7.0 + C#开发一个Web应用程序。我(访问该页面时,IE浏览),如不能连接到服务器发现VSTS 2008调试时,如果我叫Response.Close()方法的Page_Load(请参阅以下code),就会出现错误。I am using ASP...

我使用ASP.Net +净3.5 + VSTS 2008 + IIS 7.0 + C#开发一个Web应用程序。我(访问该页面时,IE浏览),如不能连接到服务器发现VSTS 2008调试时,如果我叫Response.Close()方法的Page_Load(请参阅以下code),就会出现错误。

I am using ASP.Net + .Net 3.5 + VSTS 2008 + IIS 7.0 + C# to develop a web application. I find when debugging in VSTS 2008, if I call Response.Close() method in page_load (please refer to code below), there will be error (from IE when accessing the page) like can not connect to server.

我的问题是,

在通常情况下,当我们应该呼吁Response.Close()?或者不需要调用(依靠ASP.Net框架,自动关闭)?

BTW:我的previous理解是开发者应该随时拨打Response.Close当处理完成,在服务器端使用的Response.Write所有数据已写入客户端。我是正确?

BTW: my previous understanding is developer should always call Response.Close when processing is completed at server side and all data has been written to client using Response.Write. Am I correct?

2,为什么我在code遇到了这样的错误?什么是根本原因?

2 Why I met with such error in my code? What is the root cause?


    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("Hello World! ");
        Response.Close();
    }

在此先感谢, 乔治

thanks in advance, George

推荐答案

从的 MSDN网站这里可能是有用的:

The following from the MSDN website might be useful here:

本方法终止于突然的方式连接到客户端,但不适合用于正常的HTTP请求的处理。该方法发送一个复位分组到客户端,这可能会导致在间被丢弃该缓冲在服务器上的响应数据时,客户端,或其他地方。

This method terminates the connection to the client in an abrupt manner and is not intended for normal HTTP request processing. The method sends a reset packet to the client, which can cause response data that is buffered on the server, the client, or somewhere in between to be dropped.

您可以针对恶意的HTTP客户端使用这种方法来攻击。但是,通常你应该叫CompleteRequest,而是如果你想提前跳到EndRequest事件并传送到客户端的响应。

You might use this method in response to an attack by a malicious HTTP client. However, typically you should call CompleteRequest instead if you want to jump ahead to the EndRequest event and send a response to the client.

阅读全文

相关推荐

最新文章