I want to reduce postback in one of my application page and use ajax instead. I used the WebMethod to do so.. I have a static WebMethod that needs to access the session variables and modify. and on the client side, i am calling this method using jQuery. I tried accessing the session as follows:
[WebMethod]
public static void TestWebMethod()
{
if (HttpContext.Current.Session["pitems"] != null)
{
log.Debug("Using the existing list");
Product prod = (Product)HttpContext.Current.Session["pitems"];
List<Configs> confs = cart.GetConfigs();
foreach (Configs citem in confis)
{
log.Info(citem.Description);
}
}
log.Info("Inside the method!");
}
The values are displayed correctly and seems to work.. but i would like to know if this practice is allowed as the method is a static methods and would like to know how it will behave if multiple people access the application.
I would also like to know how developers do these kind of tasks in ASP if this is not the right method.
Thanks in advance for your suggestions and ideas,
Abdel Olakara
Static methods are completely safe to use. The problem some people run into with the fields being shared across requests only occurs with static fields, because they are indeed shared within the same process.
I think your method is a good way of going about this. This is exactly what web methods are for.
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