I'm new to Mvc.
Sorry to my english. ^^
I have some question about asp.net MVC session in the controller.
The Scenario things that I want to do is like follows..
1. First of all, My development circumstance is entityframework and mvc3.
2. When Someone logged in each one has different database. So, Each has connect different database.
3. So, Each person has his own session value which is database connection string. So far so good.
4. I have simple database Repository and at the each repository's constructor can change database connection.
5. At controller which calls Repository class, I need session value. But As I know Controller's construction can't keep session value. right?
6. I want your good advice. Thanks in advance.
Code samples are below:
public class MasterRepository
public MasterRepository(string con)
_db = new DBEntities(con);
public class TestController : Controller
private string con;
_db = new MasterRepository(Session["conn"].ToString()); }
public ActionResult Index()
string con = Session["conn"].ToString();
I just want to use my session value to my controller so I want to keep my database connection in a controller's contructor.
The point is not set to an controller's contructor.
_db = new MasterRepository(Session["conn"].ToString());
I want to use _db variable to my Testcontroller.
If impossible set session value to controller's constructor, Is there another way?
[Edited]Code is blocked in "pre" tags[/Edited]