Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 C#3.0 C# ASP.NET C#4.0 , +
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 11-Jun-12 20:48pm
Mac123341.1K
Comments
Member 8910048 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

Thanks&Regards
Nagasiva
  Permalink  
Comments
MAC123456 at 12-Jun-12 2:03am
   
One Query
Why this problem is occurring ??
I have to write this lines in User.aspx page??
nagasiva at 12-Jun-12 2:05am
   
plz share u r code in user.aspx page
nagasiva at 12-Jun-12 2:09am
   
if(!IsPostBack)
try this code
string strsession="";
strsession=Session["Name"].ToString();
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hello
Just Write like that in page load of user.aspx
 
if(!IsPostBack)
{
         String SessionName = String.Empty;
         SessionName = Session["Name"].ToString();
          
}
 
Now You Can Access SessionName variable the value for Session Value
 
Thank You
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

in user.aspx page_load() event write the following code
 
string sessionData=Session["name"];
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

In User page try to get the session by following method:
 
string name = Request["Name"].ToString();

 
For more information you may check the following link:
 
Exploring Session in ASP.NET[^]
 

Thanks,
Tajbir
  Permalink  
Comments
MAC123456 at 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
MAC123456 at 12-Jun-12 2:29am
   
It's throwing exception
Object reference not set to an instance of an object.
Sk. Tajbir at 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 at 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" %>
MAC123456 at 12-Jun-12 5:26am
   
If we write
string name = Request["Name"].ToString();
than it will return the session["Name"] 's value????
Sk. Tajbir at 12-Jun-12 6:01am
   
yes it will return the value stored in the session.

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

  Print Answers RSS
0 OriginalGriff 230
1 PIEBALDconsult 150
2 DamithSL 125
3 Andreas Gieriet 90
4 Jochen Arndt 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 22 Oct 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100