Click here to Skip to main content
13,357,583 members (67,839 online)
Rate this:
Please Sign up or sign in to vote.
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

Posted 11-Jun-12 20:48pm
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
Rate this: bad
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
     string strsession='';
try this code

MAC123456 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
try this code
string strsession="";
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Just Write like that in page load of user.aspx

         String SessionName = String.Empty;
         SessionName = Session["Name"].ToString();

Now You Can Access SessionName variable the value for Session Value

Thank You
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

in user.aspx page_load() event write the following code

string sessionData=Session["name"];
Rate this: bad
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[^]

MAC123456 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 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" %>
MAC123456 12-Jun-12 5:26am
If we write
string name = Request["Name"].ToString();
than it will return the session["Name"] 's value????
Sk. Tajbir 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180111.1 | Last Updated 22 Oct 2014
Copyright © CodeProject, 1999-2018
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