Thursday, January 22, 2015

HttpContext.Current.Items & HttpContext.Current.Sessions

Difference between HttpContext.Current.Session and HttpContext.current.Item.
HttpContext.Current.Item” data will be there  for single HTTP Request/Response 

HttpContext.Current.Session data will be there throughout user’s session.

HttpContext.Current.Item It stores data for very short term,i.e data stored here for very short period. Items collection in HttpContext is an IDictionary key-value collection 

HttpContext.Current.Item 
Eg

HttpContext.Current.Items["Value"] = "Hi";

To Retrieve the data


HttpContext.Current.Items["Value"]

Note: Here the data will be lost , when we send request to the server

Example




.cs Page




Output:
When the page is loaded, the following output is displayed.



On Button Click





Note:
Here we can see on Button Click , the values of HttpContext.Current.Items["Value"] is null as show in debugging mode




The life of Items collection is very short and it only cover single HTTP request.
Session life time is more.

No comments:

Post a Comment

Thank you for visiting my blog

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...