Search code examples
asp.nethttprequestwebmethod

ASP.NET Webmethod in aspx.cs page not able to access Page.Request object


Does anyone know how to access HttpRequest.Cookies within a static method with [WebMethod] attribute from an aspx.cs page?

It won't let me do it because method is static .

[WebMethod]
public static bool PostToTwitter(string identityUrl, string message, bool autoFollow)
{
  Page.Request.Cookies -- object reference is required for non-static field

Thanks!


Solution

  • Use,

    HttpContext.Current.Request.Cookies