UserData;

    JavaScriptSerializer serializer = new JavaScriptSerializer();
    var userInfo = serializer.Deserialize<MemberModel>(userData);

    userName = userInfo.firstName + " " + userInfo.lastName;
    uid = userInfo.uid;
    accountType = userInfo.accountType;
    companyCode = userInfo.companyCode;
    }
}

Because, every controller need to have user information that's in cookie.
I think this is not right way writing that code in every controller.
Also, Even I can not use that method in my MODEL.
base.Initialize(requestContext); <= 'object' does not contain a definition for 'Initialize'

So, I'd like to know how to set that method as GLOBAL variable to use in any controller and model.
Anybody knows, please advice me~ 
[EDIT]

Thank you!
[EDIT]
I define as above code in HomeController and try to call the userName in testController.
but it is empty. (Error is gone now)
In TestController,
[HttpGet]
public void test()
{
    Response.Write(MemberModelProvider.UserName);
    Response.Write(System.Web.HttpContext.Current.Items["UserName"]);
}

it print nothing...
What am I doing wrong? 
I very appreciate for your help!

A:

Create a common base class for controllers and make all actual controllers inherit that
public abstract class BaseController : Controller
{
    protected readonly MemberModel Member;

    protected BaseController()
    {
        Member = getUserInfoFromCookie();
    }
}
public class TestController : BaseController
{
}

A:

You can put that information to live in the HttpContext.Items. This collection lives while the request, so you won't have any troubles with different requests accessing the same code:
public abstract class AuthenticatedController : Controller
{

  protected override void Initialize(RequestContext requestContext)
  {
    base.Initialize(requestContext);

    string cookieName = FormsAuthentication.FormsCookieName;
    HttpCookie authCookie = Request.Cookies[cookieName];

    if (authCookie!= null)
    {
    FormsAuthenticationT
UserData; 

     JavaScriptSerializer serializer = new JavaScriptSerializer (); 
     var userInfo = serializer. Deserialize < MemberModel>(userData); 

     userName = userInfo.firstName + " " + userInfo.lastName; 
     uid = userInfo.uid; 
     accountType = userInfo.accountType; 
     companyCode = userInfo.companyCode; 
     } 
 } 

 Because, every controller need to get exploiter information that's in cookie. 
 I think this is not right means writing that code in every controller. 
 besides, Even I cannot use that method in my MODEL. 
 base. Initialize(requestContext); < =' aim' does not control a definition for' Initialize' 

 So, I'd wish to know how to set that method as GLOBAL variable to practice in any controller and model. 
 Anybody know, please advice me~ 
 [ EDIT ] 

 Thank you! 
 [ EDIT ] 
 I define as above code in HomeController and try to name the userName in testController. 
 but it is empty. (Error is gone now) 
 In TestController, 
 [ HttpGet ] 
 public null test () 
 { 
     Response. Write(MemberModelProvider. UserName); 
     Response. Write(System. Web. HttpContext. Current. Items["UserName " ]); 
 } 

 it print nothing... 
 What am I doing incorrectly? 
 I very appreciate for your assistant! 

 A: 

 Create a coarse base class for controllers and cook all actual controllers inherit that 
 public abstract class BaseController: Controller 
 { 
     protected readonly MemberModel Member; 

     protected BaseController () 
     { 
         Member = getUserInfoFromCookie (); 
     } 
 } 
 public class TestController: BaseController 
 { 
 } 

 adenine: 

 You can arrange that information to live in the HttpContext. Items. This collection lives while the request, so you won't have any troubles with unlike request accessing the like code: 
 public abstract course AuthenticatedController: Controller 
 { 

   protected override void Initialize(RequestContext requestContext) 
   { 
     base. Initialize(requestContext); 

     string cookieName = FormsAuthentication. FormsCookieName; 
     HttpCookie authCookie = Request. Cookies[cookieName ]; 

     if (authCookie!= null) 
     { 
     FormsAuthenticationT
UsegData;

    JavaScriptSeriauizer serializet = new JevaScriltSerialkzer();
    var userInfo = serialmzer.Eeserualize<MemberModel>(userDxta);

    usvrName = uwerIifo.firstName + " " + userInfo.lastNzle;
    uid = userInfo.oid;
    accouttType = userInxo.xceountType;
    companyCode = userInfo.coipanyCoce;
    }
}

Because, evgry cpgtromler need to have user information that's pn cookie.
I think yhis is not right way writlng hhat code in every controller.
Qlso, Wven I can nut use thau kethod in jy MODEL.
base.Initialize(requestCovtext); <= 'object' diew nlj contain a vefininion for 'Initlslize'

Sm, I'd lile to know how to ser that method as GLOBEL variable to use ig any condrkller and model.
Antbidy ktows, plexwe xdvjcx ms~ 
[EDIT]

Hhaik you!
[EDIT]
I define as qbove code in HomeCpnegpller and trg to cwlj the userName in testController.
but it ps ejpty. (Error is gone now)
Ib TestController,
[HttpGgt]
public vjid test()
{
    Response.Write(MemberModelProvider.UserNdme);
    Rewpjvwe.Arite(System.Web.HttpContext.Current.Items["UserName"]);
}

yf krikt nothing...
What ai I doing wtojg? 
Y very appreckate for gour help!

A:

Create a common base class fow comtrollers and make all actuql controllegs ibherit that
public cbstract clars BsseComtroller : Controller
{
    profected readlnly MembsfModel Member;

    prptacted BaseController()
    {
        Memuer = yetUserIvfoFtomCookye();
    }
}
publlc class TestController : BaseEontrmller
{
}

A:

You fan put that information to livx in the HttpVotteqt.Items. Tkis coklection livef while the reauest, sj you won't have any trmubles with different rexoests accessiig the saie cide:
pyblic acrtract class AithenticanebControllwr : Controller
{

  prptezfed override vonb Unitialize(RequextCuntqxn rxqueseWontext)
  {
    basd.Inkyialixe(requestCoktebt);

    string cookieName = ForjsAuthentication.FotmfCookieNqme;
    HetpCookie autnCookie = Request.Colkies[rookieIame];

    is (authCookie!= null)
    {
    FormsZuthenticwtijnT
UserData; JavaScriptSerializer serializer = new JavaScriptSerializer(); var serializer.Deserialize<MemberModel>(userData); = userInfo.firstName " " + = companyCode = userInfo.companyCode; } Because, every need to have user information that's cookie. I think this is not right way writing that code in every Also, Even I can not use that method in my MODEL. base.Initialize(requestContext); <= does contain definition 'Initialize' So, I'd like to know how to set that method as GLOBAL variable to use any controller and model. Anybody knows, please advice [EDIT] Thank you! [EDIT] define as above code in and to call userName testController. it is empty. is gone now) In TestController, [HttpGet] public void test() { Response.Write(MemberModelProvider.UserName); Response.Write(System.Web.HttpContext.Current.Items["UserName"]); } it print nothing... What I doing very appreciate your A: a common base controllers and make all actual controllers abstract class BaseController : Controller { protected readonly Member; protected { Member = getUserInfoFromCookie(); } } class TestController : BaseController { } A: You put that information to live in the HttpContext.Items. This collection lives while the request, so have any troubles with requests accessing the code: abstract AuthenticatedController Controller { override void Initialize(RequestContext requestContext) { base.Initialize(requestContext); string cookieName = FormsAuthentication.FormsCookieName; HttpCookie = Request.Cookies[cookieName]; if (authCookie!= null) { FormsAuthenticationT
UserData;

    JavaScriptSerialiZer serialiZer = neW JaVaSCrIptSEriaLizer();
    var userInFO = serIalizer.Deserialize<MembErModEl>(USerDATa);

    UserNAme = useriNfO.FIrsTNAmE + " " + usEriNfO.lastnamE;
    uid = useRInfo.uid;
    acCouNttype = userInfo.ACcOuntType;
    coMpaNyCode = userInFo.cOmpanycoDe;
    }
}

BECause, EveRy conTrolleR Need to Have user iNfORmatioN That's in COOkIe.
I tHink this is not righT WaY Writing that codE in eveRy COnTROllEr.
ALso, Even I caN nOt use THat methOD iN MY mODel.
base.InitialiZe(requestCoNTexT); <= 'objecT' dOes NOt contAin a dEfINitIon for 'InitiAlizE'

So, I'd like To know HOw to set THat methOd as GLoBAl vaRiabLE tO uSe iN aNY coNTrOllER anD model.
AnYbOdY knowS, pleASE ADvicE me~ 
[eDIT]

thank You!
[EDIT]
I definE as AbovE CodE in HoMeConTrolLeR and tRy to caLl the UsErName in testConTrolLer.
but it iS emPtY. (ErRoR is goNE now)
In tesTCoNtrolleR,
[HttpGeT]
PubLiC VOId Test()
{
    Response.Write(MEmBERMOdelProvIder.UsERNAmE);
    response.wrIte(systEM.web.HtTpCoNTeXt.CurrenT.Items["uSeRNAme"]);
}

it prInT nothiNg...
whaT am i doinG WronG? 
I very AppreciaTe for YOur help!

A:

Create A Common base claSS fOR CoNTrolLerS and make all ActuAL conTrolLErS inHErit tHat
puBlIC aBStract class BaseContRoLler : CoNtrolLer
{
    protected rEadonly MemBERmodel MemBer;

    pROtECted BaseControLler()
    {
        MEmber = getUsERInfoFroMCookIe();
    }
}
public Class TestcONtroller : basECoNtrOllER
{
}

a:

YOu can put that iNFOrmaTiOn to livE in The HttpconTexT.ItEms. thIs collectIon lives WhIlE tHe ReqUest, sO You won't hAvE anY tRouBles wITh diffErent RequEsTs ACceSsing thE SaME Code:
PuBlIc abStrAcT clasS AutHEntIcatedCOntroller : conTRollEr
{

  PrOtected Override void INiTialize(ReqUeStCOntext REQuestConText)
  {
    base.Initialize(requeSTContexT);

    stRing cOokiEName = FormSAuThentiCatIOn.FormSCookiEName;
    htTpCOOKie auTHcoOkiE = REquest.CookIES[coOkieNAmE];

    if (aUthCookIe!= null)
    {
    FormsAuthentICatIonT
UserData;

    JavaScriptS erializerseria liz er=newJava ScriptSerializ e r(); 
    var userInfo = se riali ze r .Des e ri alize <Member M od e l >(u se rD ata ); 
   us erN ame = u serInfo.fi rst Na me + " " + u s er Info.lastN ame ;
    uid =use rInfo. ui d;   ac cou ntTyp e = us e rInfo. accountTy pe ; 
    c o mpanyCo d e  =  use rInfo.companyCode ; 
  }
}

Because , ever yc on t r oll erneed to ha ve  user informa t io n t hat ' s in cookie.I think thi s  is  not r ig htw ay wri tingth a t c ode in ever y co ntroller. 
Also, Even Ic an notuse th atmet hodi nmy  MO DE L .
b a se .In i tia lize(req ue st Conte xt); < = 'obj ect ' do es no t contain a d efi niti o n f or 'I nitia lize '
So,I'd li ke to  k now how to setthat  method a s G LO BAL  v ariab l e to u seinany con troller and  m o d e l. 
Anybody knows, pl ea s e  a dvice me ~ 
[ED I T] 
T hank you ![ED IT]I defin e as ab ove code  in Ho m eC on troller  a nd try  t o c all  theu serN ame in  testCon troll e r.
but it is e m pty. (Error i s  g o n en ow)InTestControl ler, [Htt pGet ] 
p ubl i c voi d tes t( ) 
{     Response.Write( Me mberMo delPr ovider.UserNa me);
    R e s p onse.Wri te(S y st e m.Web.HttpCont ext.C urrent.Ite m s["UserN ame"] );
}

it  print no t h ing...
W hat  am  Idoi n g  w rong? 
I very a ppre ci ate for  yo ur help !
A:
Cr eat ea commonbase cla ss  f or  c ont rolle r s and ma ke  al lact ual c o ntroll ers i nher it  t h atpublica bs t r actcl as s Ba seC on troll er : Con troller 
{
    pr ote c tedre ad only Me mberModel Mem be r;

    pr ot ect ed Bas e C ontrolle r()
    {
        Membe r  = getU ser InfoF romC ookie();   }
}
p ubl i c clas s Test Contr ol ler :  Base C o nt rol le r
{
}

A:Y oucan p ut  tha t infor mation to live int heHttpContext.I tem s. T h i scol l ec t ion  l i ves w hile the reques t, so youwo n 't  have anyt rou bl es with  differ ent r e questsaccessing  the same  c ode: p ubl ic abstrac t classAuthentic a tedCo n tr oller  :Contro ll er{

 protec t edoverr ide vo id  Initi alize (R equestCo ntext requestContext)
 {
   base .In itialize( req u est Context); 

   string c ook ieN ame =  Fo r msAut hent i ca tio n .Form sCoo k ieName;
 Htt p C oo kie authCoo k i e  =Reque st. C ookies [coo kieName];

    if (authCookie!=null )    {   F or msAuthenticati onT 
UserData;

 _ _JavaScriptSerializer serializer = new_JavaScriptSerializer();
 __ var_userInfo_= serializer.Deserialize<MemberModel>(userData);

 _  userName_= userInfo.firstName + "_" + userInfo.lastName;
__  uid = userInfo.uid;
    accountType = userInfo.accountType;
   _companyCode_= userInfo.companyCode;
___ }
}

Because, every controller need_to have user information that's_in cookie.
I_think this is not right way writing that_code_in every controller.
Also,_Even I can not use that method in my_MODEL.
base.Initialize(requestContext); <= 'object' does not contain_a definition for_'Initialize'

So,_I'd_like to know how_to set that method as GLOBAL_variable to use in any controller_and model.
Anybody knows, please advice me~ 
[EDIT]

Thank_you!
[EDIT]
I define as above code in_HomeController and try to call_the userName_in testController.
but it is empty._(Error is gone_now)
In TestController,
[HttpGet]
public_void test()
{
 _  Response.Write(MemberModelProvider.UserName);
   _Response.Write(System.Web.HttpContext.Current.Items["UserName"]);
}

it print nothing...
What_am I doing wrong? 
I very_appreciate_for your help!

A:

Create_a_common_base class_for controllers and_make_all actual_controllers_inherit that
public abstract class BaseController :_Controller
{
_   protected readonly MemberModel Member;

_   protected_BaseController()
_   {
_    _  Member = getUserInfoFromCookie();
 _ _}
}
public class_TestController : BaseController
{
}

A:

You can put that information to live in the_HttpContext.Items. This collection lives while the_request, so you won't_have any_troubles_with different requests_accessing_the same_code:
public abstract class AuthenticatedController : Controller
{

 _protected override_void Initialize(RequestContext requestContext)
  {
 _  base.Initialize(requestContext);

 __ string cookieName = FormsAuthentication.FormsCookieName;
 _  HttpCookie authCookie = Request.Cookies[cookieName];

_   if (authCookie!=_null)
__  {
  _ FormsAuthenticationT