Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi to all,
Here i using session value in normal page.now i want to pass in app_Code file page (logic page i need the session value).following below code is used in my application but i occur null values.

Normal page code: (.CS)

C#
string mac1 = string.Empty;

      
      string mac1 = string.Empty;

        string mac = string.Empty;
        //  GetMACAddress();
        mac = macAddress.Value;

       // 

        Session["macAddress"] = mac;
        mac1 = Session["macAddress"].ToString();



In APP_CODE
logic.cs:-
string mac2 = System.Web.HttpContext.Current.Session["macAddress"].ToString();

but this code return null. how to access session value in app_code. Kindly help for this task.
Posted
Updated 19-Jun-15 0:37am
v2
Comments
Sinisa Hajnal 19-Jun-15 6:33am    
Are you sure you're setting the value?
JOTHI KUMAR Member 10918227 19-Jun-15 6:35am    
sorry what??
jaket-cp 19-Jun-15 6:49am    
I believe what Sinisa is asking, have you set the session value, as in the Normal page code: (.CS)
Session["macAddress"] = mac;

Also click on the reply to the comment, otherwise I do not believe the person who made the comment will get a notification.
JOTHI KUMAR Member 10918227 19-Jun-15 6:51am    
hmm yeah

Hi

You must be missing something

Session values will be available through

System.Web.HttpContext.Current.Session["VariableName"]


Before getting session value you must set it .

Either you are not setting it or your session expires before you trying to get it.
 
Share this answer
 
Comments
JOTHI KUMAR Member 10918227 19-Jun-15 7:02am    
sorry im new in .net.when the session expires.how to extend the session.can you tell me
By default, Session timeouts are 20 minutes in ASP.NET. To increase the timeout or expiry you have to change the timeout attribute for SessionState in the web.config file

<sessionstate timeout="40" />


If you are using Forms authentication, You have to adjust this attribute:

<authentication mode="Forms">
          <forms timeout="40" />
    </authentication>
 
Share this answer
 

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



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