Link to home
Create AccountLog in
Avatar of rgagli1
rgagli1

asked on

Using the Login Control and want to store the username as a session

I am creating a login page using the Wizard control and I want to create a session to refer to the username throughout the site.  How can I do this?  The session will be used to insert records into a database. I see that they have a loginname control but can I use this control to insert the username?
Avatar of ICINTRACOM
ICINTRACOM

The easiest way is to grab the user name from the page that the user logged into.  So on load of the page use this.

Session("UserName") = User.Identity.Name

Also place this at the top of your page.

Imports System.Web.Security

You don't really need to put the name in Session if you don't want to because you can use the User.Identity.Name just about anywhere that the user is logged into.

hth
Avatar of rgagli1

ASKER

I'm using VB.  Do I still need Imports System.Web.Security?

ASKER CERTIFIED SOLUTION
Avatar of ICINTRACOM
ICINTRACOM

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
you choose the zone as .NET, Programming for ASP.NET, Microsoft Visual Basic.Net and you are saying "I'm using VB". What do you mean by that?

if you are using ASP.NET, then

when you use a login form, then user can enter any valid user name and in that case you cannot use User.Identity.Name as the logged in user. You have to take the values from the login form as. ( just drag login control from tools )

Session("UserName")=Login1.UserName
Session("Password")=Login1.Password