在页面方法中,如何访问当前请求对象以便读取标头?
该方法看起来像
 [System.Web.Services.WebMethod]
 public static string MyMethod(string name)
 {
 }
并且生活在一个继承自 Page 的 aspx.cs 文件中
在页面方法中,如何访问当前请求对象以便读取标头?
该方法看起来像
 [System.Web.Services.WebMethod]
 public static string MyMethod(string name)
 {
 }
并且生活在一个继承自 Page 的 aspx.cs 文件中
您可以Request.Headers在代码中使用属性
[System.Web.Services.WebMethod]
 public static string MyMethod(string name)
 {
   var headers = HttpContext.Current.Request.Headers;   
   foreach(var item in header)
   {
   }
 }
    您将不得不使用HttpContext.Current
[WebMethod]        
public static string MyMethod(string name)
{
      var headers = HttpContext.Current.Request.Headers;         
} 
HttpContext.Current返回与当前请求关联的HttpRequest 。您可以使用它来处理与请求关联的任何数据。