sharing data among controllers and pages
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 ap开发者_开发百科p 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
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.
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).
精彩评论