Jarrod Everett
Jarrod Everett

Reputation: 801

Accessing Page Method Request Headers

Inside a page method, how can I get access to the current request object so that I can read the headers?

The method looks like

 [System.Web.Services.WebMethod]
 public static string MyMethod(string name)
 {
 }

And lives in an aspx.cs file that inherits from Page

Upvotes: 1

Views: 936

Answers (2)

nunespascal
nunespascal

Reputation: 17724

You will have to use the HttpContext.Current

[WebMethod]        
public static string MyMethod(string name)
{
      var headers = HttpContext.Current.Request.Headers;         
} 

HttpContext.Current returns the HttpRequest associated with the current request. You can use it to process any data associated with the request.

Upvotes: 0

Aghilas Yakoub
Aghilas Yakoub

Reputation: 28970

you can use Request.Headers property in your code

[System.Web.Services.WebMethod]
 public static string MyMethod(string name)
 {
   var headers = HttpContext.Current.Request.Headers;   
   foreach(var item in header)
   {

   }
 }

Upvotes: 1

Related Questions