Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I would like to know how to access a session["xx"] assigned in a controller, in session_end(global.asax) without using "static" or "this.session" and which takes its specific instance (this.session )
Posted
Comments
sgeorge106 12-Mar-15 1:49am    
I need to access in session_end (Global.asax) ?

1 solution

You do not need to be using any of these clauses of keywords to access the values of session variables. Just use this,

C#
var val = Session["x"];


But since the variable might not exist, instead of above code, use the following to ignore any runtime errors,

C#
if(Session["x"] != null) {
   // variable exists
   var val = Session["x"]; 
}


Now val would have the value set in the Session variable for x. You can use these variable in any page on the application, they exist throughout the session.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900