Best practice when using WebMethods and session
Posted
by Abdel Olakara
on Stack Overflow
See other posts from Stack Overflow
or by Abdel Olakara
Published on 2010-05-15T10:46:41Z
Indexed on
2010/05/15
10:54 UTC
Read the original article
Hit count: 406
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
© Stack Overflow or respective owner