473,503 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using session variables with C# to let a page know whether you are logged in or not

57 New Member
Hi, I'm developing a web application using ASP .Net and C# as code behind.

On my home page Index.aspx I have login textbox's so if you correctly enter your username and password it says "You have successfully logged in". Then the C# performs the code Session["loggedIn"] = "true"; meaning that the application knows that the user is logged in.

Now whenever the user goes to the page ClassList.aspx there is a button at the top saying Start. Whenever the user presses Start, if he is logged in the user controls for that page appear, although if he is not logged in the following message appears: "You need to log in to use this section of the site".

The way that I am doing this is that I am saying in ClassList.aspx: if(Session["loggedIn"].Equals("false")) then show error message else show user controls.

The problem that I am having is that the user can access ClassList.aspx without initially going to the Index.aspx page and therefore if he presses Start, the system will not recognise the Session["loggedIn"] variable.

Can anybody think of any way of sorting this problem out as its doing my head in!

Thanks
Mar 28 '08 #1
2 1642
nateraaaa
663 Recognized Expert Contributor
You also need to check to see if your Session variable is null. If the Sesion variable is null then the user has not logged in yet.

Expand|Select|Wrap|Line Numbers
  1.  if(Session["loggedIn"] != null) 
  2. if(Session["loggedIn"].Equals("false"))
  3. {
  4. }
  5. }
  6. else
  7. {
  8. //inform user that they must be logged in to access this page.
  9. }
  10.  
Nathan
Mar 28 '08 #2
moorcroft
57 New Member
that works perfect thanks very much!

Andy
Mar 28 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2238
by: Dave Smithz | last post by:
Hi there, I have implemented a login sequence using session variables for a PHP/MySQL DB which I took over development. I read some books and this NG and it seemed straight forward. However the...
3
1519
by: JP SIngh | last post by:
Hi All We have an ASP application which tracks holidays for our employees. When the user logs in we store thier username in a session variable and use that variable when displaying and adding...
14
2161
by: Coleen | last post by:
Hi All :-) We have an APSX application using VB.net as the code behind, which uses one or two session variables per page. These Session variables are passed to the final page and calculations...
2
3184
by: dana lees | last post by:
Hello, I am using session variables in a cs class file. I am inserting a sortedList to a session variable like this: System.Web.HttpContext.Current.Session = EventsSortedList; Later on,...
1
2859
by: VMI | last post by:
When my webpage loads the first time, I fill my datatable with records from the DB and display them in my gridview. Once it loads, the user clicks on a button and add records to the datatable,...
1
1459
by: =?Utf-8?B?U00=?= | last post by:
Background We migrated our Asp.net 1.1 application to Asp.net 2.0 ( just migration ) .. It was working fine in local developer machine and one of our development testing server. When we moved...
6
5121
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
3
1196
by: Mark Rae [MVP] | last post by:
"Lloyd Sheen" <a@b.cwrote in message news:uL5TPXPvIHA.1688@TK2MSFTNGP06.phx.gbl... Surely that will throw an exception because you're trying to populate a DataSet variable with an object...
8
2886
by: adarshyam | last post by:
hi.. I am new to vb.net i am doing a program using dynamic textboxes which involves two pages .. where values of textboxes in one page must be transfered to to other sex of textboxes in another page,...
0
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5576
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.