Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is accessing session through HttpContext.Current bad [practice]?

I am trying out signalR and followed their Chat sample with a few modifications. So, in the ChatHub.cs, I tried to access the user's session variable and found out that I couldn't. So I've searched the web for answers and found this: Access to Session from a Hub

So as commented by Mr. David Fowl, accessing session variables through HttpContext.Current is bad. Is it really that bad that I should avoid using it? I really need to access the session variable.

like image 673
PenguinBlues Avatar asked May 26 '26 12:05

PenguinBlues


1 Answers

I am guessing the reason it is bad is because your code will not work if hosted outside of the asp.net context. Since HttpContext.Current is web specific

like image 82
rpgmaker Avatar answered May 30 '26 06:05

rpgmaker



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!