Best practice when using WebMethods and session
- by Abdel Olakara
Hi all,
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