Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 14th, 2006, 12:06 PM
Authorized User
 
Join Date: Feb 2006
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem using session

Hi, need some help here with sessions...
I'm facing some problem using session for my login page for my web application...
In other pages, I don't have any problem and I'm not sure why.

What is supposed to happen:
1. User Logs in (secure/login.aspx)
   User id is stored as in session object
2. User redirected to account details (admin/acct.aspx)
   User id is retrieved from session object and printed using response.write

Below shows part of the code i've used:

In login.aspx:
Code:
    FormsAuthentication.SetAuthCookie(Me.txtbox_LoginID.Text, False)
    Session.Add("LoginID", Me.txtbox_LoginID.Text)
    Response.Redirect("../admin/acct.aspx")
In acct.aspx:
Code:
    response.write(Session("LoginID"))
Problem: The Login ID is not printed! I did a step through of the code and the count for number of items stored in session = 0 when it should be 1!

I've used the above methods for other pages to store other types of values and they all work. But for this particular login page, it just does not work!

Any help is greatly appreciated!

Thanks.

Scripts82
__________________
Scripts82
 
Old December 14th, 2006, 12:23 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

What happens if you try to write this value to the screen:

Response.Write(User.Identity.Name.ToString());

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old December 14th, 2006, 12:44 PM
Authorized User
 
Join Date: Feb 2006
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi dparsons, that works, in fact I have got around by using User.Identity.Name.ToString() and Request.ServerVariables("AUTH_USER")

However, my problem remained unsolved because I still need to pass other variables via the session object...

The code i showed is a simplified version...
The full code will first connect to a database, check the account type of the user and write some variables to the session object for use in other pages...

Any clues?

Thanks!

Scripts82
 
Old December 14th, 2006, 12:50 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

In so far as why your session object is empty i dont know, this is syntactly correct:

Session.Add("LoginID", Me.txtbox_LoginID.Text)

And, presumeably, it should have a value associated with it. It seems that there is a bug in your code somewhere that is setting this value to nothing. I am not sure. Like i said, the code you provided is accurate.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old December 14th, 2006, 12:55 PM
Authorized User
 
Join Date: Feb 2006
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hmm... yep... it seemed rather weird...

i'll keep trying till end of the day to see if i can get it working... otherwise i'll just find some other way to get by this...

thanks for the prompt reply!


Scripts82
 
Old December 14th, 2006, 01:52 PM
Authorized User
 
Join Date: Feb 2006
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

somehow, after fiddling it worked... not sure why, but hope this last!

Scripts82
 
Old December 14th, 2006, 02:01 PM
Authorized User
 
Join Date: Feb 2006
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok... i finally figured out why!

in my login form, at the Page_Load code, the i have the following code:

Code:
  Session.Abandon()
  FormsAuthentication.SignOut()
I've forgotten to enclose them in a "Not isPostBack" block and hence, the sessions keeps getting killed!

the final code that worked:
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If Not IsPostBack Then
      Session.Abandon()
      FormsAuthentication.SignOut()
    End If
End Sub

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
    FormsAuthentication.SetAuthCookie(Me.txtbox_LoginID.Text, False)
    Session.Add("LoginID", Me.txtbox_LoginID.Text)
    Response.Redirect("../admin/acct.aspx")
End Sub
I guess sometimes when one is new, he'll need to learn things the hard way...

Scripts82
 
Old December 14th, 2006, 02:07 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

lol ya that would do it! =]

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature





Similar Threads
Thread Thread Starter Forum Replies Last Post
Session Out Problem kasipandian J2EE 3 March 21st, 2008 03:35 PM
session problem MunishBhatia ASP.NET 2.0 Professional 9 October 6th, 2007 04:06 AM
Session problem abdulweb General .NET 3 August 27th, 2007 08:01 PM
session and cookie problem (empty session file) msincan BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 February 27th, 2005 05:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.