Tuesday 15 July 2014

asp.net mvc - "Global" Access to Variable -



asp.net mvc - "Global" Access to Variable -

i'm starting out asp.net mvc (4).

throughout app, depend on employee key. can key database via current user's username accessible me via user.identity.name.

rather repeat look-up throughout controllers, right way look-up 1 time , store in variable can accessed across controllers?

you can save on cookie way:

dim cookie new httpcookie("somenameforcookie")

and set variables on cookie way:

cookie("name1") = "some value can integer etc" cookie("name2") = 2

to cookie do:

httpcontext.current.request.cookies.get("somenameforcookie")

and read values cookie same way set values (cookie("name1") etc).

you can also save session variables way:

session("name3") = 3

a 3rd way create controller base of operations class. inherit all/some of controllers it. when gets filled value (protected or public) available throughout controllers.

asp.net-mvc

No comments:

Post a Comment