访问响应头从ASP.Net PageMethod的电话电话、ASP、Net、PageMethod

2023-09-10 17:25:28 作者:古风

在使用ASP.Net Ajax来调用PageMethods,我怎么可以从成功的方法访问HTTP响应头?

When using ASP.Net Ajax to call PageMethods, how can I access the Http response headers from the "success" method?

例如:

PageMethods.DoSomething(
   function(result){successMethod(result)},
   function(error){errorMethod(error)}
);

function successMethod(result){
    //------how can I access the Http response headers from here? ------
}

感谢您的帮助

Thanks for any help

推荐答案

在你的榜样,PageMethods.DoSomething应该有一个返回值相等的 WebRequest的,如果​​它是一个asp.net web服务代理。这是在这样您就可以处理请求你发起它(即取消等)之后。

In your example, PageMethods.DoSomething should have a return value equal to WebRequest if it's an asp.net web service proxy. This is provided so that you can manipulate the request after you've initiated it (i.e. cancel it etc).

通过这个类,你有,你可以用它来添加一个处理的Web请求完成时为add_completed方法。回调的签名是函数OnWebRequestCompleted(执行者,EventArgs的)执行程序在此参数可以得到持有额外的响应信息。例如,你可以弄个响应头与 executor.getAllResponseHeaders();这应该是头名和值的映射(命名的集合)。

With this class you have an add_completed method which you can use to add a handler for when the web request completes. The signature for the callback is function OnWebRequestCompleted(executor, eventArgs), and the executor parameter in this enables you to get hold of extra response information. For example, you can get hold of the response headers with executor.getAllResponseHeaders(); which should be a map (named collection) of header names and values.

所以,如果你做的服务方法调用后立即添加一个处理的Web请求的完成时,它应该工作(有一个在世界上可以应对连续的速度比两行code无网络服务!)。

So if you add a handler to the web request's completed event immediately after making the service method call, it should work (there's no web service in the world that can respond faster than two consecutive lines of code!).

在previous超链接的WebRequest 包含一个完整的例子如何把这个功能。但是请注意,这code直接使用的WebRequest。

The previous hyperlink to WebRequest contains a full example of how wire this up. Notice, however, that this code uses the WebRequest directly.

Asp.Net Ajax的Web服务代理类使用 WebServiceProxy 类,每个代理方法最终调用它的引用方法,它返回的WebRequest 实例。

Asp.Net Ajax Web Service proxy classes use the WebServiceProxy class, and each proxy method ultimately call its invoke method, which returns the WebRequest instance.