I want to store my global data till its inserted into DB. so, i want to implement a customer class which can handle creating and storing session values. So, below is my code.
public static class SessionHelper
{
private static int custCode;
public static int PropertyCustCode
{
get
{
return custCode;
}
set
{
if (!string.IsNullOrEmpty(HttpContext.Current.Session[propertyCode].ToString()))
{
custCode = value;
}
else
{
throw new Exception("Property Code Not Available");
}
}
}
public static void MakePropertyCodeSession(int custCode)
{
try
{
HttpContext.Current.Session[propertyCode] = custCode;
}
catch(Exception ex)
{
}
}
I am Assigning Property Code from my webpage like below
SessionHelper.MakePropertyCodeSession(7777);
and after this i want to access session value like below
int propertyCode=SessionHelper.PropertyCustCode;
But, I am not able to access session values. Every time, I am getting as null
value. Why? where is my mistake?