lundi 7 septembre 2015

Thead-safe static variable to keep Logged-in user

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

Aucun commentaire:

Enregistrer un commentaire