I am populating an instance of a class that represents the session variable and exists in a class library. I need to populate one property that requires me to get access to the Request
object. I understand that I can use the System.Web.HttpContext.Current.Request
to get the request object?
Is this a good practice. Something tells me that I should be doing this in the controller (or the base controller) that has the System.Web
namespace.
It is stored in the memory of the server and the value is available for the entire lifetime of the request.
There is no difference. The getter for Page. Session returns the context session. Save this answer.
Current. Item” data is live for single HTTP request/Response where HttpContext. Current. Session data is live throughout user's session.
Its not a bad practice - the object is available - if you design dictates to access it there - then by all means do it. One option is to pass in an instance of the request to the class's constructor if it makes you feel cleaner : )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With