How To Store User ID In Session

Feb 15, 2011

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.

View 5 Replies

Similar Messages:

Perform User Management (store User Info, Login , Logout Etc) Without Using Session Or Cookie?

Dec 1, 2010

Is it possible to perform user management (store user info, login , logout etc) without using session or cookie?

View 3 Replies

Forms Data Controls :: Store Gridview Datatable In Session And Then Retrieve From Session And Store Database

Nov 11, 2010

Its related to datatable in gridview store in session and then session retrive and store to database. basically i am using gridview here creating new row for button click and these row adding untill user's last entry then submit all these entry to database. so i want to use session variable to store this data temporarily and after final entry user click on submit button and all data shold be save in db.

View 9 Replies

MVC :: How To Store Persistent-user-session Information's

Aug 8, 2010

i have a list of fields that i would store for all the user session. I thought to create a class, insert the information in it and store the class in the session but i'm not sure this is the best way to do it (performances, etc). I should have a list of these informations that i can display in views, i can delete and i can update. How could i do this?

View 10 Replies

Session, FormsAuthenticationTicket, Store Data About The User?

Feb 1, 2011

I'm am building an web application that needs to be able to scale.We want to store, an connection string, an object that says what organization the user is working on right now and the identity of the user.

We could serialize down this and send through the userdata property in the FormsAuthenticationTicket, but that feels to not be the optimal solution, cause its is 4-5 strings of data that is unncessesary, but the main issue is that we are sending an encrypted connectionstring to the user which we dosent want to.

So what are our options?Can ASP.NET Cache be our solution?, can we couple the expiration of the cache and the formsauthenticationcookie?

View 2 Replies

Store Form Data In Tables For User Session?

Jan 5, 2010

I am using Visual Studio 2008.

I created a New Project ASP.NET Web Application.

I created a Textbox named VisitorName. The visitor puts in their name and it goes in VisitorName.Text

There is a Label that says "Which do you own?"

There is a RadioButtonList. It has Cat, Dog and None.

There is a button that says Add to list.

The button needs to add the results of the above items and put them in the list.

Now you keep adding people and their pets.

Once there are all entered you press send and I get the results for everyone entered during that session via email.

I have no database access and the information does not need to be stored in such a way.

I would like to use a datatable or datalist or something to that sort.

Oh and I would like the visitor to be able to click on a name in the table and edit the data using the form controls not in the datalist or datatable itself.

View 8 Replies

State Management :: How To Store A Large Amount Of Data In User's Session

Sep 29, 2010

I need to store a large amount of data in user's session but I guess using Session Object is not the best way of doing that. Is there any other way around??? Remember I don't have small variables to store, I have large collections.

View 5 Replies

Master Pages - Where's The Best Place To Store Custom "User" Object For The Duration Of Session

Jul 6, 2010

I have an ASP.NET application that needs to remember some info about a user (and what company they are from) across pages, within a session. I imagine this is a requirement of just about any ASP.NET application of a certain size. I've used a few different approaches over the years. In the past, I've passed around an id in querystring parameters like so: [URL] and then instantiated the object on each page (from the database). Another common way of doing it is storing my objects in session variables:

Session["User"] = currentUser; // store at login
User currentUser = (User)Session["User"]; // retrieve on some other page

which saves a trip to the DB, but I worry about memory used if the User object is complex and the site has many concurrent users. I have recently inherited an application that uses public properties on the master page, like this:

Master.theUser = currentUser; // store at login
User currentUser = Master.theUser; // retrieve on some other page

This saves the cast, and looks more readable to me I think, but I don't know if it's better or worse performance-wise. It also has some logic in the getter where if the private value is null, it tries to get it from the Session variable, though I'm not sure if that's never used (or used every get!?) or what. My latest idea is to use my page class. I have a custom page class derived from the standard System.Web.UI.Page base class. It includes objects like CurrentUser as public properties. This seems to work OK. I like it even better. But I really don't know what's going on under the covers. Can anyone give an opinion on which approach is better and why?

Update: I've done some checking use trace.axd and Trace.Write and it looks like neither the masterpage version nor the custom page class version "remember" the values between pages. The "get" methods have a line of code that checks if the User property is null, and if so, reads it from the session variable. This happens when a page accesses the property (Master.User or the derived class's this.User) for the first time on a given page, then subsequent requests can get the value (without going to the session variable). So thus far the best solution looks something like this:

public class MyPage : System.Web.UI.Page
private User user;
public User User
if (user == null)
user = (User)HttpContext.Current.Session["CurrentUser"]; //check if session[CurrentUser] is null here and log them out if so?
return user;
user = value;
HttpContext.Current.Session["CurrentUser"] = value;

Then on any webpage.aspx.cs, you can do something like this: UsernameTextBox.Text = User.FullName;

View 2 Replies

C# - Store Class Properties In Session And Use Of Session Handler - Is It Good Design

Jul 27, 2010

I have a class called EditMapUtilities. Here are some class properties that I want to persist:

public class EditMapUtlities
public static Boolean isInitialEditMapPageLoad
get { return SessionHandler.isInitialEditMapPageLoad; }
set { SessionHandler.isInitialEditMapPageLoad = value; }

Here is my SessionHandler Class following the pattern from this post Static Session Class and Multiple Users:
using System.Web.SessionState;

public static class SessionHandler
private static HttpSessionState currentSession
if (HttpContext.Current.Session == null)
throw new Exception("Session is not available in the current context.");
return HttpContext.Current.Session;
//A boolean type session variable
private static string _isInitialEditMapPageLoad = "EditMapInitialPageLoad";
public static bool isInitialEditMapPageLoad
if (currentSession[_isInitialEditMapPageLoad] == null)
return true;
return (Boolean)currentSession[_isInitialEditMapPageLoad];
currentSession[_isInitialEditMapPageLoad] = value;

I am still learning OOAD. I want to keep relevant properties with relevant classes. I also want to keep all Session stored variables in one place for ease of maintenance and to encapsulate the session keys and calls. I feel like my design is too coupled though. How can I make it more loosely coupled? Is my editMapUtilities class too tightly coupled to the SessionHandler class? How would you do it better?

View 2 Replies

Web Forms :: Store Values In Session Array And Get Back The Values From Session ?

Oct 1, 2010

i have two text boxes and one button in web form. I need to display the contents of text boxes in a datatable in the same form, when i click on the button.

How can i do this using session array. I need to store values in session array. and get back the values from session when i need .

View 2 Replies

How To Store A Value Into A Session Variable And Load From That Value Back From The Session Variable

Nov 22, 2010

Currently in an .aspx file, I am storing a value (filename that was created in that session) in an hidden text box. When the user clicks on the "Print" labeled Hyperlink control, it opens the file that was stored in the hidden text box control. But when the user goes to different screen (in the same session), I loose the filename value that is stored in the hidden text box control. So I would like to store the filename variable in a session variable. So that if the user leaves this .aspx file and comes back to this .aspx file I can load the value into the hidden text box from the session variable.

View 11 Replies

Security :: Userid Of Newly Created User / To Store Additional Details Of The User In Another Database Table

Nov 10, 2010

Our application lets the administrator create new users. Since the administrator is logged in, I have set Logincreateduser = false so that the administrator is not logged out even after creating the new user.

The problem is :I need the userid of the newly created user to store additional details of the user in another database table. I see that i can get the username using Createuserwizard1.username; but how do I get the userID?

View 2 Replies

Security :: Store User Password In Custom Membership User

Aug 12, 2010

I have a custom membership user class and custom MembershipProvider working against database. Due to security reasons the user passwords are stored in the database as hashed values. So my procedure

public override bool ValidateUser(string username, string password) is
//select hashed password from db
return (EncodePassword(password) == dbpassword)

View 4 Replies

How To Store The Value In Label2 Row 8 In A Session Variable

Mar 11, 2010

I have a datalist that shows Label, Label2 and has 8 rows of data.

I would like to store the value in Label2 row 8 in a session variable... how can i do this in

View 7 Replies

Web Forms :: Store Value Without Session - Static

Jan 21, 2010

I am currently working on 3.5 with C#. In our application Link buttons are used in Grid to redirect page. means when user click on link from Home Page it will redirect to Job details and when user click on Job details link grid it will redirect to VehicleDetail page. My problem is how to store value on jobDetails page from which page user came. without using Session , Static variable when page is redirect.

View 5 Replies

C# - How To Store A List Of Objects In Session

Jun 24, 2010

i want to store a list of objects in session

List<ContentQueueLog> inactiveContent = GetInActiveContent(this.userID, this.visitorID);

when i store this list in sesssion it is stored but while trhying to get its null.

View 1 Replies

MVC :: Does C# Uses Session Internally To Store The States

Nov 11, 2010

Does MVC Uses Session internally to store the states ?

Wil MVC faile across Webfarms if session not managed properly ?

View 6 Replies

Store Session In A Collection (key, Value) During One Page?

Jan 19, 2010

How can I store session in a collection (key, value) during one page. I must be able to add and remove items.
Is there an existing control?

View 14 Replies

How To Store Ten Textbox Control In Session State

Dec 22, 2010

i am working on a web application. i have 10 textbox control, in the page and 6 check box control . i need to store all those values in a session. but storing such a big field value is nothing but to create more session values. but i dont want create more than one session variables. how should i do this.

View 1 Replies

How To Store Value In Session If In Browser Cookie Is Disabled

Dec 1, 2010

Can i still store value in session if in browser cookie is disabled?

View 2 Replies

C# - Store Data From A Form For Recovery From The Session?

Feb 15, 2011

I need to store data from a form for recovery from the session.

Below is my rough first attempt for a generalized method for textboxes:

Load Session:


However, it appears that the Controls collection is not working for me. What am I doing wrong?

this.Controls.OfType<TextBox>() yields no results at run time when I do a quick watch on it.

View 4 Replies

C# - Store Viewstate In The Session Rather Than Bulking Up The HTML

Jan 7, 2011

I'm trying to get to store viewstate in the session rather than bulking up the html.

Now i've read that comes with the SessionPageStatePersister which can be used instead of the default HiddenFieldPageStatePersister to do this. I was wondering how i go about dropping it in?

This is what i've got so far:

I think i need to create a PageAdapter that returns a SessionPageStatePersister from its GetStatePersister method, and somehow get the page to use this pageadapter. But Page.PageAdapter only has a getter, so i'm not sure how you set it.

See the 'remarks' heading here: [URL]

View 3 Replies

C# - Store Multiple Values In A Session Variable?

Jan 9, 2011

consider this scenario: a user on my website has a profileID. There are some pluginID's associated with this profileID.

E.g.: User1 might have 2, 3 and 5 plugins associated with his profile.

When the user logs in, I store the profileID of the user in a session variable cod. ON a certain page, the user tries to edit the plugins associated with his profile. So, on that page, I have to retrieve those pluginID's from the DB.

I have applied this code but this fetches only the maximum pluginID from the DB and not all the pluginID's.


I was trying to figure out how can I store multiple pluginID's in this session variable?

View 2 Replies

State Management :: Use Session To Store Code - How To Use Cookies

Aug 5, 2010

I am using session to strore code

if (!string.IsNullOrEmpty(Request.QueryString["c"]))
System.Web.HttpContext.Current.Session["Code"] = Request.QueryString["c"];
System.Web.HttpContext.Current.Session["Code"] = "GR";

Instead of session,now I want to use cookies.

View 8 Replies

C# - Store Session Cookie For Groups Of Subdomains IIS7?

Jan 6, 2011

I have an application running ASP.NET. I have different domains and different sub-domains. I want the domains to share session with their sub domains.

For Example, the following domains access this application:


If a user goes to and, I want it to use the same session. If the user were to go to and, I would want it to use a different session than the *

The way I used to handle it was a hack in page_load that works perfectly in IIS6:

Response.Cookies["ASP.NET_SessionId"].Value = Session.SessionID;
Response.Cookies["ASP.NET_SessionId"].Domain = SiteUtility.GetCookieDomain();

(SiteUtility.GetCookieDomain would return or depending on the url of the request) Unfortunately, this no longer seems to work for iis7. Each subdomain/domain a user goes to, the user gets a new session cookie.

I then found the web.config entry: '<httpCookies domain="" />. This works great for sharing session cookie between subdomains. Unfortunately, this completely screws up session state for *

View 3 Replies

Copyrights 2005-15, All rights reserved