Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all

I have made a 2 pages
1.Login Page.
2.User Page.

In the Login page i setted a session variable
Session["Name"] = "abc";

i can access the session variable using Response.Write in login page.

After that I redirecting to User.Aspx page ,but in this page(user.aspx) I can't access the session variable.

please help why i can't access the session variable in the next page.

Please Help

Thanks
Posted
Comments
Member 8910048 13-Jun-12 1:03am    
Please verify that whether SessionState mode is OFF or not. If Mode is off, you should be enable Mode="inproc" or other than OFF mode

go to page_Load event
write this code for acessing the session for 1st time load
code
C#
if(!IsPostBack)
     string strsession='';
strsession=Session["Name"];
try this code


Thanks&Regards
Nagasiva
 
Share this answer
 
Comments
Mac12334 12-Jun-12 2:03am    
One Query
Why this problem is occurring ??
I have to write this lines in User.aspx page??
nagasiva 12-Jun-12 2:05am    
plz share u r code in user.aspx page
nagasiva 12-Jun-12 2:09am    
if(!IsPostBack)
try this code
string strsession="";
strsession=Session["Name"].ToString();
Hello
Just Write like that in page load of user.aspx

C#
if(!IsPostBack)
{
         String SessionName = String.Empty;
         SessionName = Session["Name"].ToString();
          
}


Now You Can Access SessionName variable the value for Session Value

Thank You
 
Share this answer
 
v2
in user.aspx page_load() event write the following code

string sessionData=Session["name"];
 
Share this answer
 
In User page try to get the session by following method:

C#
string name = Request["Name"].ToString();


For more information you may check the following link:

Exploring Session in ASP.NET[^]


Thanks,
Tajbir
 
Share this answer
 
Comments
Mac12334 12-Jun-12 2:19am    
One query
Why this type of problem occurred ???Can you please explain me briefly .
means:Why i can't access the session variable
Mac12334 12-Jun-12 2:29am    
It's throwing exception
Object reference not set to an instance of an object.
Sk. Tajbir 12-Jun-12 2:40am    
you are getting an exception because there is no value in the session. I think you are having this problem because of your browser. Please go to the browser setting and allow browser to store cookie. That might help you.
Sk. Tajbir 12-Jun-12 2:50am    
Also please check whether you session is enable or not. To enable your session go to the top of your pages and put EnableSessionState="true" in <% %>. Example:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="login.aspx.cs" EnableSessionState="true" %>
Mac12334 12-Jun-12 5:26am    
If we write
string name = Request["Name"].ToString();
than it will return the session["Name"] 's value????

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