c# - Global Variables vs. ASP.NET Session State -
this going sound rather naive, i'm developing web application spans multiple pages. of these pages instantiate same class object w/ methods accesses cms using api. currently, when user starts creating content, i'm storing variables folder id content located in session variable.
my question this: can instantiate single instance of class can used across pages without having on every page? if so, each person accessing page given own version of class? assume using static variables , methods isn't way go since shared in memory. , also, where/how declared if going used globally in web application in .net c# application?
i recommend making base class inherits system.page. have page code behind inherit that.
then, inside base class, create property reference object. example, this:
public class basepage : system.web.ui.page { public foo currentfoo { { return (foo)session["foosessionobject"]; } set { if(session["foosessionobject"]==null) { //instantiate new 1 session["foosessionobject"] = new foo(); } session["foosessionobject"] = value; } } }
then, anywhere in page, currentfoo. , have access of properties.
this makes nice , clean code behinds.
Comments
Post a Comment