1

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

user426306
  • 903
  • 1
  • 7
  • 11
  • What are you trying to achieve? Can't come up with many things you would want this behavior for. – bastijn Sep 27 '10 at 11:11
  • nothing big just want to show city of logged in person after fetching it from database at time of login in all views using their controller not master page becoz i also need that for further sql queries. – user426306 Sep 27 '10 at 11:26
  • You topic start is a bit confusing. Take your time writing it and also be sure to "upvote" or "accept" the answer which was the solution to your problem. I couldn't help noticing all of your questions are still open with no upvotes or accepted answer from your side. When something fixes your problem, let other people know so they will know what answer is the correct one when stumbled upon your question having the same problem themselves. – bastijn Sep 27 '10 at 12:12
  • ok i will do that and rectify that.. thanks – user426306 Sep 28 '10 at 04:30

2 Answers2

0

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
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • 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? – user426306 Sep 27 '10 at 11:22
  • 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 Sep 27 '10 at 11:25
  • 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 Sep 27 '10 at 11:49
0

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).

Community
  • 1
  • 1
bastijn
  • 5,841
  • 5
  • 27
  • 43