storing user ID in session

When the user logs in, I want to store his userID in the session with

HttpContext.Current.Session["UserID"] = 2354; (this is just a hard-coded example)

Then, when I run a page method, if I do

var test = HttpContext.Current.Session["UserID"];

will the variable test hold the value I stored when he logged in?

If this is a correct way of doing it, how do I access the session when I receive a call from a page method? I want to put the test =... line in a page method to identify which user the request is coming from.

Thanks.

6
задан NotMe 15 February 2011 в 21:49
поделиться