开发者

Access Response Headers from ASP.Net PageMethod Call

开发者 https://www.devze.com 2022-12-15 17:27 出处:网络
When using ASP.Net Ajax to call PageMethods, how can I access the Http response headers from the \"success\" method?

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

For example:

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

function su开发者_运维知识库ccessMethod(result){
    //------how can I access the Http response headers from here? ------
}

Thanks for any help


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).

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.

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!).

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 Service proxy classes use the WebServiceProxy class, and each proxy method ultimately call its invoke method, which returns the WebRequest instance.


A web request has a headers collection

http://msdn.microsoft.com/en-us/library/bb383774.aspx

The webrequestmanager is a static object that you may be able to extract this information from:

http://msdn.microsoft.com/en-us/library/bb397435.aspx

Hopefully, between the two links, it makes sense :-;

I'm not saying recode to use this necessarily, but page methods is a wrapper and as such I think it would access information from a web request, which can be affected from the WebRequestManager...

0

精彩评论

暂无评论...
验证码 换一张
取 消