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!
They're static because they are entirely stateless, they don't create an instance of your page's class and nothing is passed to them in the request (i.e. ViewState and form field values).
The WebMethod attribute is added to each method we want to expose as a Web Service. ASP.NET makes it possible to map traditional methods to Web Service operations through the System. Web. Services. WebMethod attribute and it supports a number of properties that control the behavior of the methods.
Use,
HttpContext.Current.Request.Cookies
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With