0

i am trying to get the current user session from a static function, but the usObj is always null.

here is what i'm doing:

public static List<RequestTypeBL> GetRequestType(string itemNo, int requestTypeID, int claimID) {
    UserSession usObj = (UserSession)HttpContext.Current.Session["UserSessionObj"];
    RequestTypeBL reqTypeBL;
    reqTypeBL= SERT_BO.RequestTypeBL.GetClaimRequestType(claimID, requestType, usObj.UserID, itemNo);

am i missing something? please help.

i am able to do the following from regular functions just fine:

return (UserSession)Session["UserSessionObj"];

i am seeing this behavior in our production environment only, when the same code is run in development,everything works as it should. could it have something to do with an IIS setting of some sorts?

Mark Hall
  • 53,938
  • 9
  • 94
  • 111
Madam Zu Zu
  • 6,437
  • 19
  • 83
  • 129
  • 1
    There's a lifecycle associated with Session. Are you sure what you're trying to access exists at the point that you're trying to do this? – JamieSee Jun 08 '12 at 16:14
  • @antisanity, HttpContext.Current already returns the current context, why you advise to add another parameter to the function? – walther Jun 08 '12 at 16:21
  • 2
    you probably dont run ur methods in the same order with the static and the instance methods. But we cannot really tell without more code – YavgenyP Jun 08 '12 at 16:22
  • @YavgenyP - what do you mean i don't run them in the right order? i thought they were both returning the same same values? – Madam Zu Zu Jun 08 '12 at 16:26
  • Any threading involved here? Parallel.ForEach? Task? – Marc Gravell Jun 08 '12 at 16:43
  • @xrum the basic concept of using a static method with a session works, hence im guessing the problem is in the way you are using the method /session and not the method itself. Where do you store the "UserSessinObj" in the session, for example? What method and when does that? – YavgenyP Jun 08 '12 at 16:48

1 Answers1

1

Something similar happened to me once and it was because of the amount of worker threads that the application pool was using, the development webserver used only one. The request were not always answered by the same thread. I don't remember where to configure that on IIS, not sure you are using IIS either. Hope it helps.

Johann Pérez
  • 367
  • 1
  • 16