0

I am currently developing a web application on C# Web API.

I am thinking about having a static variable to keep track of currently logged in user. So I don't have to pass the session object or user object back and forth between controllers and models.

Sample code:

using System;

namespace Model.TwoScoopsOfASP
{
    public class SessionHelper
    {
        [ThreadStatic] public static Member.Member loggedMember;
    }
}

Since I am quite new to this tech stack so I couldn't see if there is any big problem with this approach. Please help me to point any big issue that you can think of.

Note: I haven't implemented the Thread-safe singleton pattern so please ignore it for now. Thanks

Toby D
  • 1,465
  • 1
  • 19
  • 31
  • check this out http://stackoverflow.com/questions/2692144/keeping-track-of-logged-in-users – Vinoth Sep 08 '15 at 04:54
  • @Vinoth thank you for your suggestions but I don't think that answers my question – Toby D Sep 08 '15 at 05:37
  • You must rely on session object. It is the best aproach, otherwise how would you make a relation between a request and the user that is making the request?. Of course, you will have to wrap the session into a clever class that hides the fact that you are relying on the session bag. – George Lica Sep 08 '15 at 05:44

1 Answers1

0

You must rely on session object. It is the best aproach, otherwise how would you make a relation between a request and the user that is making the request?. Of course, you will have to wrap the session into a clever class that hides the fact that you are relying on the session bag. Another aproach would be to use tokens ... but i don't think you will want to do this since a session behind the scenes is just another kind of token ...

George Lica
  • 1,798
  • 1
  • 12
  • 23
  • Yeah, exactly. The idea is to put the session into the common threadstatic class. This should save effort of passing session around. The question is whether there is any potential issue with this approach. – Toby D Sep 08 '15 at 06:13