c# - Reduce global state in web applications -



c# - Reduce global state in web applications -

there numerous posts available on alternatives global state, have lingering questions regarding implementation in web environment.

in asp.net, values stored in session practically global variables, seems can't reasonably store, e.g., authenticated username, permissions, etc. across pages , events without resorting session[] collection. (i typically utilize dependency injection, wouldn't want pass these values in viewstate/url client.)

so take global state necessary evil in web development (due stateless nature of http) , reply utilize responsibly. facade pattern implementation? static class such 1 below gets , sets values in session doesn't much mask global state.

public class sessionwrapper { public static string username { { homecoming convert.tostring(session["username"]); } set { session["username"] = value; } } public static bool isauthenticated { { homecoming convert.toboolean(session["isauthenticated"]); } set { session["isauthenticated"] = value; } } }

global variables problematic global values fine. if want mitigate “problems” of global state create objects immutable (i don't see how di relevant).

the user property of httpcontext object useful storing such state since needs available every part of application can assigned in pipeline.

so, come own implementation of system.security.principal.iprincipal has properties want , assign httpcontext.current.user during, say, authenticaterequest event.

c# asp.net web-applications global-variables session-variables

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -