473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

User Name

I am writing a webapp in which a user is required to enter a login id and
password on a login form. I have forms authenticaion coded in my web.config.
Once the user is logged in, I want to use the login id in other forms of the
app. I will eventually save a record to a SQL database, and I want the login
id to be automatically entered in a field on a form other than the login
page. Help.
Nov 18 '05 #1
15 2880
Session variables.

Eliyahu

"Tom Nowak" <To******@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
I am writing a webapp in which a user is required to enter a login id and
password on a login form. I have forms authenticaion coded in my web.config. Once the user is logged in, I want to use the login id in other forms of the app. I will eventually save a record to a SQL database, and I want the login id to be automatically entered in a field on a form other than the login
page. Help.

Nov 18 '05 #2
How do I define and use them?

"Eliyahu Goldin" wrote:
Session variables.

Eliyahu

"Tom Nowak" <To******@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
I am writing a webapp in which a user is required to enter a login id and
password on a login form. I have forms authenticaion coded in my

web.config.
Once the user is logged in, I want to use the login id in other forms of

the
app. I will eventually save a record to a SQL database, and I want the

login
id to be automatically entered in a field on a form other than the login
page. Help.


Nov 18 '05 #3
Tom Nowak <To******@discussions.microsoft.com> typed:
How do I define and use them?


After the authentication process insert the value in a session variable

Session["UserId"] = UserId;

To use the variable

if(Session["UserId"] != null)
int UserId = Int32.Parse(Session["UserId"]);

If you need more info about your authenticated user, you could consider to
create your own user object, populate it after the authentication process
and than save it in a session variable. For example:

//user is authenticated

UserInfo user = new UserInfo();
user.Id = UserId;
user.Name = Name;
user.Email = Email;

Session["CurrentUser"] = user;

Than, when you need to retrieve this information ......

if(Session["CurrentUser"] != null)
UserInfo user = (UserInfo)Session["CurrentUser"];

int Id = user.Id;
string Name = user.Name;
string Email = user.Email;

.....and so on.

If you need to recover only the name of the current authenticated user, you
could use the Current.User.Identity.Name.

--
Davide Vernole
MVP ASP/ASP.NET
Microsoft Certified Solution Developer
Nov 18 '05 #4
=?Utf-8?B?VG9tIE5vd2Fr?= <To******@discussions.microsoft.com> wrote in
news:AF**********************************@microsof t.com:
I want to use the login id in other forms of the
app.


You can use user.indentity.name to retrieve the name of the logged in user.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 18 '05 #5
When I try to display the value of user.identity.name, this value is blank.
After the user enters a valid id and password, the value is still blank.
Help.
"Lucas Tam" wrote:
=?Utf-8?B?VG9tIE5vd2Fr?= <To******@discussions.microsoft.com> wrote in
news:AF**********************************@microsof t.com:
I want to use the login id in other forms of the
app.


You can use user.indentity.name to retrieve the name of the logged in user.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 18 '05 #6
=?Utf-8?B?VG9tIE5vd2Fr?= <To******@discussions.microsoft.com> wrote in
news:E1**********************************@microsof t.com:
When I try to display the value of user.identity.name, this value is
blank. After the user enters a valid id and password, the value is
still blank. Help.


Oh I think you need to assign the name when you do the FormAuthentication.
There is a parameter you can set the name.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 18 '05 #7
The value will be blank if using Forms authentication until after you are
authenticated.

Do you have the whole Forms authentication structure setup and running
correctly?

After you think you are logged in call this: User.Identity.IsAuthenticated.
That will tell you if you really got authenticated or not.

If User.Identity.IsAuthenticated Then
Dim username as string = User.identity.name
End If

If User.Identity.IsAuthenticated is not returning true then you havn't
probably setup Forms authentication.

Do you have this (or something similar) in your web.config?

<authentication mode="Forms">
<forms loginUrl="login.aspx" />
</authentication>

In your login.aspx to you have login button that calls:

RedirectFromLoginPage

It is in this method that you set what the username will be, so that you can
read it back using User.Identity.Name.

HTH,
Greg
"Tom Nowak" <To******@discussions.microsoft.com> wrote in message
news:E1**********************************@microsof t.com...
When I try to display the value of user.identity.name, this value is
blank.
After the user enters a valid id and password, the value is still blank.
Help.
"Lucas Tam" wrote:
=?Utf-8?B?VG9tIE5vd2Fr?= <To******@discussions.microsoft.com> wrote in
news:AF**********************************@microsof t.com:
> I want to use the login id in other forms of the
> app.


You can use user.indentity.name to retrieve the name of the logged in
user.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 18 '05 #8
Heres the code from the login button:

Dim con As SqlConnection

con = New SqlConnection("data source=ten;initial
catalog=fbpoolSQL;trusted_connection=yes;")

con.Open()
Dim drd1 As System.Data.SqlClient.SqlDataReader
drd1 = StatusDataReader(con)

Do While drd1.Read

If drd1.GetString(1) = txtLogin.Value And _
drd1.GetString(2) = txtPwd.Value Then

Me.lblMessage.Text = "Successful"
GoTo sucrtn

End If

Loop

Me.lblMessage.Text = "Login ID or Password not valid."
txtLogin.Value = ""
txtPwd.Value = ""
GoTo endrtn

sucrtn:

Response.Redirect("choices.aspx")

endrtn:

End Sub

Heres part of my web.config:

<authentication mode="Forms">
<forms loginUrl="login.aspx" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
"Greg Burns" wrote:
The value will be blank if using Forms authentication until after you are
authenticated.

Do you have the whole Forms authentication structure setup and running
correctly?

After you think you are logged in call this: User.Identity.IsAuthenticated.
That will tell you if you really got authenticated or not.

If User.Identity.IsAuthenticated Then
Dim username as string = User.identity.name
End If

If User.Identity.IsAuthenticated is not returning true then you havn't
probably setup Forms authentication.

Do you have this (or something similar) in your web.config?

<authentication mode="Forms">
<forms loginUrl="login.aspx" />
</authentication>

In your login.aspx to you have login button that calls:

RedirectFromLoginPage

It is in this method that you set what the username will be, so that you can
read it back using User.Identity.Name.

HTH,
Greg
"Tom Nowak" <To******@discussions.microsoft.com> wrote in message
news:E1**********************************@microsof t.com...
When I try to display the value of user.identity.name, this value is
blank.
After the user enters a valid id and password, the value is still blank.
Help.
"Lucas Tam" wrote:
=?Utf-8?B?VG9tIE5vd2Fr?= <To******@discussions.microsoft.com> wrote in
news:AF**********************************@microsof t.com:

> I want to use the login id in other forms of the
> app.

You can use user.indentity.name to retrieve the name of the logged in
user.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/


Nov 18 '05 #9
=?Utf-8?B?VG9tIE5vd2Fr?= <To******@discussions.microsoft.com> wrote in
news:45**********************************@microsof t.com:
Heres the code from the login button:

Dim con As SqlConnection

con = New SqlConnection("data source=ten;initial
catalog=fbpoolSQL;trusted_connection=yes;")

con.Open()
Dim drd1 As System.Data.SqlClient.SqlDataReader
drd1 = StatusDataReader(con)

Do While drd1.Read
Wow... your code is pretty bad. Just do a "SELECT FROM TABLE WHERE
USERNAME = NAME AND PASSWORD = PASSWORD to retrieve ONE record. There's
no need to loop through all the records.
If drd1.GetString(1) = txtLogin.Value And _
drd1.GetString(2) = txtPwd.Value Then

Me.lblMessage.Text = "Successful"
GoTo sucrtn
Gotos?! Don't use Gotos! Gotos create spagetti code ; )
End If

Loop

Me.lblMessage.Text = "Login ID or Password not valid."
txtLogin.Value = ""
txtPwd.Value = ""
GoTo endrtn

sucrtn:

Response.Redirect("choices.aspx")
You should be using the FormAuthentication class instead.

i.e. FormsAuthentication.RedirectFromLoginPage(txtUser. Text,
chkPersistLogin.Checked)

endrtn:

End Sub

Heres part of my web.config:

Nov 18 '05 #10
Is that actually a GoTo statement? :^)

You need to use RedirectFromLoginPage to set the username.

FormsAuthentication.RedirectFromLoginPage(txtLogin .Value, False)

Greg

"Tom Nowak" <To******@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...
Heres the code from the login button:

Dim con As SqlConnection

con = New SqlConnection("data source=ten;initial
catalog=fbpoolSQL;trusted_connection=yes;")

con.Open()
Dim drd1 As System.Data.SqlClient.SqlDataReader
drd1 = StatusDataReader(con)

Do While drd1.Read

If drd1.GetString(1) = txtLogin.Value And _
drd1.GetString(2) = txtPwd.Value Then

Me.lblMessage.Text = "Successful"
GoTo sucrtn

End If

Loop

Me.lblMessage.Text = "Login ID or Password not valid."
txtLogin.Value = ""
txtPwd.Value = ""
GoTo endrtn

sucrtn:

Response.Redirect("choices.aspx")

endrtn:

End Sub

Heres part of my web.config:

<authentication mode="Forms">
<forms loginUrl="login.aspx" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
"Greg Burns" wrote:
The value will be blank if using Forms authentication until after you are
authenticated.

Do you have the whole Forms authentication structure setup and running
correctly?

After you think you are logged in call this:
User.Identity.IsAuthenticated.
That will tell you if you really got authenticated or not.

If User.Identity.IsAuthenticated Then
Dim username as string = User.identity.name
End If

If User.Identity.IsAuthenticated is not returning true then you havn't
probably setup Forms authentication.

Do you have this (or something similar) in your web.config?

<authentication mode="Forms">
<forms loginUrl="login.aspx" />
</authentication>

In your login.aspx to you have login button that calls:

RedirectFromLoginPage

It is in this method that you set what the username will be, so that you
can
read it back using User.Identity.Name.

HTH,
Greg
"Tom Nowak" <To******@discussions.microsoft.com> wrote in message
news:E1**********************************@microsof t.com...
> When I try to display the value of user.identity.name, this value is
> blank.
> After the user enters a valid id and password, the value is still
> blank.
> Help.
>
>
> "Lucas Tam" wrote:
>
>> =?Utf-8?B?VG9tIE5vd2Fr?= <To******@discussions.microsoft.com> wrote in
>> news:AF**********************************@microsof t.com:
>>
>> > I want to use the login id in other forms of the
>> > app.
>>
>> You can use user.indentity.name to retrieve the name of the logged in
>> user.
>>
>> --
>> Lucas Tam (RE********@rogers.com)
>> Please delete "REMOVE" from the e-mail address when replying.
>> http://members.ebay.com/aboutme/coolspot18/
>>


Nov 18 '05 #11
My thoughts exactly.

Greg
Wow... your code is pretty bad.

Nov 18 '05 #12
dude!

Imports System.Web.Security

You might consider doing some research on forms authentication. Buy a book
(or three). That is what I did.

Greg

"Tom Nowak" <To******@discussions.microsoft.com> wrote in message
news:50**********************************@microsof t.com...
I try to use the statement below, but get an error. Thanks for the help.

"Greg Burns" wrote:
Is that actually a GoTo statement? :^)

You need to use RedirectFromLoginPage to set the username.

FormsAuthentication.RedirectFromLoginPage(txtLogin .Value, False)

Greg

"Tom Nowak" <To******@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...
> Heres the code from the login button:
>
> Dim con As SqlConnection
>
> con = New SqlConnection("data source=ten;initial
> catalog=fbpoolSQL;trusted_connection=yes;")
>
> con.Open()
> Dim drd1 As System.Data.SqlClient.SqlDataReader
> drd1 = StatusDataReader(con)
>
> Do While drd1.Read
>
> If drd1.GetString(1) = txtLogin.Value And _
> drd1.GetString(2) = txtPwd.Value Then
>
> Me.lblMessage.Text = "Successful"
> GoTo sucrtn
>
> End If
>
> Loop
>
> Me.lblMessage.Text = "Login ID or Password not valid."
> txtLogin.Value = ""
> txtPwd.Value = ""
> GoTo endrtn
>
> sucrtn:
>
> Response.Redirect("choices.aspx")
>
> endrtn:
>
> End Sub
>
> Heres part of my web.config:
>
> <authentication mode="Forms">
> <forms loginUrl="login.aspx" />
> </authentication>
> <authorization>
> <deny users="?" />
> </authorization>
>
>
> "Greg Burns" wrote:
>
>> The value will be blank if using Forms authentication until after you
>> are
>> authenticated.
>>
>> Do you have the whole Forms authentication structure setup and running
>> correctly?
>>
>> After you think you are logged in call this:
>> User.Identity.IsAuthenticated.
>> That will tell you if you really got authenticated or not.
>>
>> If User.Identity.IsAuthenticated Then
>> Dim username as string = User.identity.name
>> End If
>>
>> If User.Identity.IsAuthenticated is not returning true then you havn't
>> probably setup Forms authentication.
>>
>> Do you have this (or something similar) in your web.config?
>>
>> <authentication mode="Forms">
>> <forms loginUrl="login.aspx" />
>> </authentication>
>>
>> In your login.aspx to you have login button that calls:
>>
>> RedirectFromLoginPage
>>
>> It is in this method that you set what the username will be, so that
>> you
>> can
>> read it back using User.Identity.Name.
>>
>> HTH,
>> Greg
>>
>>
>> "Tom Nowak" <To******@discussions.microsoft.com> wrote in message
>> news:E1**********************************@microsof t.com...
>> > When I try to display the value of user.identity.name, this value is
>> > blank.
>> > After the user enters a valid id and password, the value is still
>> > blank.
>> > Help.
>> >
>> >
>> > "Lucas Tam" wrote:
>> >
>> >> =?Utf-8?B?VG9tIE5vd2Fr?= <To******@discussions.microsoft.com> wrote
>> >> in
>> >> news:AF**********************************@microsof t.com:
>> >>
>> >> > I want to use the login id in other forms of the
>> >> > app.
>> >>
>> >> You can use user.indentity.name to retrieve the name of the logged
>> >> in
>> >> user.
>> >>
>> >> --
>> >> Lucas Tam (RE********@rogers.com)
>> >> Please delete "REMOVE" from the e-mail address when replying.
>> >> http://members.ebay.com/aboutme/coolspot18/
>> >>
>>
>>
>>


Nov 18 '05 #13
Sorry for being so un-knowledgable. I add the Imports statement, and use the
FormsAuthentication.RedirectFromLoginPage(txtLogin .Value, False) in the
Login Button code. I have it designed so that if the user id and password
are correct, the progem redirects the user to another page. Once I am in the
other page, I want the userid displayed in a label. How do I call up the
userid in this new page?

Sorry for the ignorance, but you really have been a big help. I have
already changed the code for finding a record.

Can you recommend a good book regarding this subject?

Thanks again.

"Greg Burns" wrote:
dude!

Imports System.Web.Security

You might consider doing some research on forms authentication. Buy a book
(or three). That is what I did.

Greg

"Tom Nowak" <To******@discussions.microsoft.com> wrote in message
news:50**********************************@microsof t.com...
I try to use the statement below, but get an error. Thanks for the help.

"Greg Burns" wrote:
Is that actually a GoTo statement? :^)

You need to use RedirectFromLoginPage to set the username.

FormsAuthentication.RedirectFromLoginPage(txtLogin .Value, False)

Greg

"Tom Nowak" <To******@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...
> Heres the code from the login button:
>
> Dim con As SqlConnection
>
> con = New SqlConnection("data source=ten;initial
> catalog=fbpoolSQL;trusted_connection=yes;")
>
> con.Open()
> Dim drd1 As System.Data.SqlClient.SqlDataReader
> drd1 = StatusDataReader(con)
>
> Do While drd1.Read
>
> If drd1.GetString(1) = txtLogin.Value And _
> drd1.GetString(2) = txtPwd.Value Then
>
> Me.lblMessage.Text = "Successful"
> GoTo sucrtn
>
> End If
>
> Loop
>
> Me.lblMessage.Text = "Login ID or Password not valid."
> txtLogin.Value = ""
> txtPwd.Value = ""
> GoTo endrtn
>
> sucrtn:
>
> Response.Redirect("choices.aspx")
>
> endrtn:
>
> End Sub
>
> Heres part of my web.config:
>
> <authentication mode="Forms">
> <forms loginUrl="login.aspx" />
> </authentication>
> <authorization>
> <deny users="?" />
> </authorization>
>
>
> "Greg Burns" wrote:
>
>> The value will be blank if using Forms authentication until after you
>> are
>> authenticated.
>>
>> Do you have the whole Forms authentication structure setup and running
>> correctly?
>>
>> After you think you are logged in call this:
>> User.Identity.IsAuthenticated.
>> That will tell you if you really got authenticated or not.
>>
>> If User.Identity.IsAuthenticated Then
>> Dim username as string = User.identity.name
>> End If
>>
>> If User.Identity.IsAuthenticated is not returning true then you havn't
>> probably setup Forms authentication.
>>
>> Do you have this (or something similar) in your web.config?
>>
>> <authentication mode="Forms">
>> <forms loginUrl="login.aspx" />
>> </authentication>
>>
>> In your login.aspx to you have login button that calls:
>>
>> RedirectFromLoginPage
>>
>> It is in this method that you set what the username will be, so that
>> you
>> can
>> read it back using User.Identity.Name.
>>
>> HTH,
>> Greg
>>
>>
>> "Tom Nowak" <To******@discussions.microsoft.com> wrote in message
>> news:E1**********************************@microsof t.com...
>> > When I try to display the value of user.identity.name, this value is
>> > blank.
>> > After the user enters a valid id and password, the value is still
>> > blank.
>> > Help.
>> >
>> >
>> > "Lucas Tam" wrote:
>> >
>> >> =?Utf-8?B?VG9tIE5vd2Fr?= <To******@discussions.microsoft.com> wrote
>> >> in
>> >> news:AF**********************************@microsof t.com:
>> >>
>> >> > I want to use the login id in other forms of the
>> >> > app.
>> >>
>> >> You can use user.indentity.name to retrieve the name of the logged
>> >> in
>> >> user.
>> >>
>> >> --
>> >> Lucas Tam (RE********@rogers.com)
>> >> Please delete "REMOVE" from the e-mail address when replying.
>> >> http://members.ebay.com/aboutme/coolspot18/
>> >>
>>
>>
>>


Nov 18 '05 #14
> Can you recommend a good book regarding this subject?

ASP.NET Unleashed, Second Edition
by Stephen Walther

http://www.amazon.com/exec/obidos/tg...books&n=507846
Once I am in the
other page, I want the userid displayed in a label. How do I call up the
userid in this new page?


lblUserName.text = user.identity.name

Greg
Nov 18 '05 #15
You should always post a new question in a new thread.

Sounds like you are rebinding your DropDownList on every post back..

Do it like this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
...
DropDownList1.DataBind
End If

End Sub

Greg

"Tom Nowak" <To******@discussions.microsoft.com> wrote in message
news:F8**********************************@microsof t.com...
I have another question regarding a DropDown List control that I am trying
to
use. I have 15 choices in the box, and I select one, but when I press a
button on the web form, the DropDownList reverts back to the 1st choice in
the box instead of the one I choose. Any Idea?
"Greg Burns" wrote:
> Can you recommend a good book regarding this subject?


ASP.NET Unleashed, Second Edition
by Stephen Walther

http://www.amazon.com/exec/obidos/tg...books&n=507846
>Once I am in the
> other page, I want the userid displayed in a label. How do I call up
> the
> userid in this new page?


lblUserName.text = user.identity.name

Greg

Nov 18 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tom Loach | last post by:
Our system administrator set up an NT server group in order to allow our users to login to our application via https to our sql server. The group appears as a User in SQL Server when you look at...
2
by: Technical Group | last post by:
Friends, Can anybody help me out by sending a piece of C# code showing how to add an active directory user to a particular user group? If the group does not exist, then create it. Thanks in...
6
by: Andrew Chalk | last post by:
My application attempts to connect to an SQL Server database as name ASPNET and Login Name SERVERNAME/ASPNET in response to these commands: SqlConnection myConnection = new SqlConnection("Data...
1
by: tony | last post by:
Hello! I just want to find out how the system find the name to set on a assembly User control dll. I have done this. 1. Create a user control - Here the namespace was set by the system to...
3
by: Dmitry | last post by:
I am trying to figure out how to pass set of credentials to System.IO Challenge is: App is running under one set of credentials, but via GUI user have a chance to enter another set. I would like...
2
by: underground | last post by:
Hi, everyone I've been trying to figure out a way for a user to update there information. I'm using sections to identify the specific user..Here is the form <? include("include/session.php");...
3
by: Terry Olsen | last post by:
I'm trying to add a domain user to a local group using the code below: Dim LCL As New DirectoryEntry("WinNT://" + Environment.MachineName + ",computer") Dim DOM As New...
2
by: dgbergman | last post by:
I have created a php login page in my site for my company. The goal is to get people into members area. Below is a list of steps that I take to create my login page in Dreamweaver CS3, can some one...
0
by: rbukkara | last post by:
Hi, I have got the following error while trying to add a user in the LDAP Directory. javax.naming.NameNotFoundException: ; remaining name 'uid=vassila,ou=People,dc=cs,dc=uno,dc=edu' I have...
14
by: chromis | last post by:
Hi, I've been trying to implement a more OOP oriented approach to dealing with user security on one of my websites, and I am trying to validate the user against an array of roles, however I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.