Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I store session data in ASP.NET?

We have a flex application that works with ASP.NET. (through weborb). And we use several data at the .NET Side to load data, ex: UserId, ChannelId, ... For now only userid is stored in the name of the HttpContext.Current.Identity. So the flex side doesn't need to push the user id all the time, but now we want to disable the "push" of the channelid too.

I was wondering where we should "store" these data. Is a Session save enough or do we need to use a cookie? or are there any other methods for this "problem".

like image 443
user29964 Avatar asked Nov 03 '25 06:11

user29964


2 Answers

I'd recommend to use Session because the values are then stored on the server (cookies are stored on the client). Also use a static class and wrap the session there.

Instead of

Session["channelid"] = ChannelId

use

SessionManager.ChannelId = ChannelId

and you can declare SessionManager as a static class with static properties that use the session. I believe this is a general Microsoft practice as well.

Cheers

like image 111
Sheraz Avatar answered Nov 05 '25 20:11

Sheraz


Session sounds like a good choice for this. Whilst there is much aversion to it unless you really do need to scale to a very large number concurrent users there is no reason to avoid it for such a small amount of data per session.

Cookies is an option however it means the data is held client-side which may not be desirable and bulks up every request being sent to the server.

like image 27
AnthonyWJones Avatar answered Nov 05 '25 20:11

AnthonyWJones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!