3 Replies - 4547 Views - Last Post: 18 December 2012 - 06:20 AM Rate Topic: -----

#1 Xna4life  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 21-February 12

[session] returns null

Posted 18 December 2012 - 03:21 AM

Im using a session variable to pass the user ID from the Index to the Create in the HomeController. ATM the user can use a drop down to select their name from the list of users and click 'View' to list the holidays they have previously booked. From there the user can click 'create' which will bring the user to a page which enables them to create a new holiday. From here they have to select their name again from the drop down list.

I want to store the users ID from the previous drop down so it will update automatically if they try to create another holiday (to replace the second drop down)

Im using a session variable to do this, iv put

Session["userameID"] = currentID;

in my view. Iv break pointed it just after and if I hold my mouse over 'currentID' it displays the correct ID of the user.

So iv tried to pass this down to the create method using

string xx = (string)Session["usernameID"];

However string 'xx' is returning NULL,., (tested with breakpoint)

I then placed the entire session in the view

Session["userameID"] = HolidayDate;

string xx = (string)Session["usernameID"];

and string 'xx' is still returning null.

Is it not meant to return the userID???

Thanks for any replys

Is This A Good Question/Topic? 0
  • +

Replies To: [session] returns null

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6062
  • View blog
  • Posts: 23,514
  • Joined: 23-August 08

Re: [session] returns null

Posted 18 December 2012 - 04:10 AM

Moved to ASP.NET
Was This Post Helpful? 0
  • +
  • -

#3 Xna4life  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 21-February 12

Re: [session] returns null

Posted 18 December 2012 - 04:19 AM

ok thanks for that, anyone have any ideas?
Was This Post Helpful? 0
  • +
  • -

#4 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 444
  • View blog
  • Posts: 1,492
  • Joined: 28-April 09

Re: [session] returns null

Posted 18 December 2012 - 06:20 AM

Is there anyway you can post the actual code where you're setting the session value and the code where you're retrieving it? In the above code you have a Session["userameID"] and a Session["usernameID"]. I'm kind of assuming one was just a typo when posting here, but if not then that could be causing a problem.

Also, something to be mindful about is that Session has a default timeout of 20 minutes. If for some reason your user moves to the second page and then has to leave their PC for some reason there's a chance that the Session value will timeout before they return which could potentially cause some problems if not handled correctly.

This post has been edited by Nakor: 18 December 2012 - 06:21 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1