in Education by

What is the difference between HttpContext.Current.Items and HttpContext.Current.Session in ASP.NET?

1 Answer

0 votes
by

Session state is one of the popular state management techniques in ASP.NET environment. We developer people play with session storage every now and then. It’s pretty simple to manage session if you understand the basic concept. Here is the syntax to do that.

  1. Session[“KEY”] =”Value”;  

Or

  1. Session[index] = ”Value”;  
  2. Let’ s a have an example: using System;  
  3. using System.Collections.Generic;  
  4. using System.Linq;  
  5. using System.Web;  
  6. using System.Web.UI;  
  7. using System.Web.UI.WebControls;  
  8. namespace WebApp  
  9. {  
  10.     public partial class WebForm1: System.Web.UI.Page  
  11.     {  
  12.         protected void Page_Load(object sender, EventArgs e)  
  13.         {  
  14.             if(!IsPostBack)  
  15.             {  
  16.                 HttpContext.Current.Items["Value"] = "Sourav Kayal in ITEM";  
  17.                 HttpContext.Current.Session["Value"] = "Sourav Kayal in SESSION";  
  18.                 Response.Write((string)(HttpContext.Current.Items["Value"]) + "<br>");  
  19.                 Response.Write((string)(HttpContext.Current.Session["Value"]));  
  20.             }  
  21.         }  
  22.         protected void Button1_Click(object sender, EventArgs e)  
  23.         {  
  24.             Response.Write((string)(HttpContext.Current.Items["Value"]) + "<br>");  
  25.             Response.Write((string)(HttpContext.Current.Session["Value"]));  
  26.         }  
  27.     }  
  28. }  

button

Related questions

0 votes
    Explain Cookie-less Session in ASP.NET?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    What are different methods of session maintenance in ASP.NET?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
    What are the different Session state management options available in ASP.NET?...
asked Apr 6, 2021 in Education by JackTerrance
0 votes
    What is the Difference between session and caching?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
    What are the differences between ASP.NET HttpHandler and HttpModule?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
    What is Data Cache in ASP.NET and how to use?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    What is authentication and authorization in ASP.NET?...
asked Apr 7, 2021 in Education by JackTerrance
0 votes
    How can we improve the Performance of an ASP.NET Web Page?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    What is Enterprise Library in ASP.NET?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    What is WebParts in ASP.NET?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
    What are the Navigations techniques in ASP.NET?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
0 votes
    What is the PostBack property in ASP.NET?...
asked Apr 8, 2021 in Education by JackTerrance
0 votes
0 votes
    What is cross-page posting in ASP.NET?...
asked Apr 7, 2021 in Education by JackTerrance
...