tags:

views:

25

answers:

2

how to share data among all web app like session . i have used session but value getting lost when i make any next request don't know weather i am making mistake or what. just want to share data among all app after fetching once from database at login time. (like session do without breaking MVC rules) thanks

no different application in same i just put HttpContext.Current.Session["city"] = value; in a data fetching class but but cant can't get this value in controller as city = (string)HttpContext.Current.Session["city"] error Object not set to an Instance

A: 

Sessions are specific to a given application. There are workarounds that allow you to share the same session between multiple applications but IMHO this is not a good design. Another approach would be to simply share an ID between those applications (either using a cookie or sending it as request parameter) and fetch the data from database.

Darin Dimitrov
ok, thanks for answer but fetching from database will make operation vary slow and cookie can be disable, cant we have solution like we had in asp.net session where we only once enter data in it and can use whenever and where ever in aspx pages and there cs files?
If you have different applications you need to share the Session between those applications. Read the article I've linked to in my answer to see how this could be achieved.
Darin Dimitrov
With "all app" he means all over the application, not between different applications. His english is just a bit funky :). @TS: one DB request to get the country is too slow?!
bastijn
A: 

Although I do not think it is good practice in your case, this SO link may help you. It explains how to use Cache to store application variables.

Remember that if you do it this way, when a user changes his country or something you app will not reflect this (or it does if you periodically refresh). I do not really understand why a simple DB request to get the country of your LoggedIn person is not suitable (speed seems odd, just one request, you probably make more on that page anyway).

bastijn