How to access session variables from any class in ASP.NET?
I have created a class file in the App_Code folder in my application. I have a session variable
I have created a class file in the App_Code folder in my application. I have a session variable
Without routing, HttpContext.Current.Session is there so I know that the StateServer is working. When I route my requests, HttpContext.Current.Session is null in the routed page. I am using .NET 3.5 sp1 on IIS 7.0, without the MVC previews. It appears that AcquireRequestState is never fired when using the routes and so the session variable isn’t instantiated/filled.
I am using ASP.NET page methods with jQuery…. How do I get the value of a session variable inside a static method in C#?
What’s the best way to authenticate and track user authentication state from page to page? Some say session state, some say cookies?
What is the maximum size a session variable can hold ? I am trying to store object in session variable, if object size is under 80 KB, then working fine and if the size is greater than 80 KB then on retrieval I am getting an exception.
As in question. Is it possible to set variable in asp.net page in localStorage and retrieve it on the other page?
So far I’ve been using Session to pass some variables from one page to another. For instance user role. When a user logs in to the web application the role id of the user is kept in Session and that role is checked at different parts of the application. I’ve recently started thinking why not use static members instead. I can store the same information in a static field and easily access it anywhere in my application (well anywhere the namespace in which that static field resides is included.) I know that using Session variables comes handy sometimes, such that:
Which method is preferred?
I’m using VS2010 and created a simple asp. web forms application, using Development Server to test it.
I try to store user data – queried from sql server – in the session, since I don’t want to access database in every request. I’m using the ‘Application_AuthenticateRequest’ and the ‘Session_Start’ methods.
First round:
AuthenticateRequest called. The following code ran:
.NET’s HttpSessionState using an “InProc” store seems to treat session variable key values as case insensitive. For example: