Search code examples
c#asp.nethttpmodule

set variable in httpmodule read in masterpage & content page, asp.net C#


Is it possible to set value to variable in httpmodule and read the value of the variable in contentpage & masterpage?

I want to use this instead of session. The variable holds the value of the userID.

Because every page on my site creates a number of different database connections i think that one more is better than having session values?! What do you think?

I want to create a site that can grow large. (Always tries to program my sites in this way) So thats why I want to take away a number of session values.

Thanks!

Mattias.


Solution

  • you can use below Code snippet.....

    //Store data in Step1:
    HttpContext.Current.Items.Add("Key", "Value");
    
    //Retrieve data in Step2:
    object value = HttpContext.Current.Items["Key"];
    

    For more detail... Read these articles.

    http://www.shubho.net/2011/01/using-httpcontextcurrentitems-as-data.html

    http://forums.asp.net/t/1476647.aspx/1