Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > How to get the USERID

Reply
Thread Tools

How to get the USERID

 
 
Doug Batchelor
Guest
Posts: n/a
 
      09-17-2006
I am using the ASP.NET membership stuff and have succesfully implemented it
on my site. However, I would now like to be able to get the UserId which is
stored for registered users in the aspnet_users table in ASPNETDB.MDF. The
reason is that I would like to include this value for users who insert
records in other tables in my database. I thought I could use the LoginName
control to get the Username which I could then use to query the aspnet_users
table, but I can't find a property which will give me the Username in the
control.

I would appreciate any help from the gurus out there.


 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      09-18-2006
Hi Doug,

Can you get it from the Profile? If so, here's some code that might get you
going.

Let us know?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>
<%@ import namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
If Not IsNothing(Profile.UserName) Then
SqlDataSource1.SelectParameters.Item _
("UserName"). _
DefaultValue = Profile.UserName
Else
SqlDataSource1.SelectCommand = ""
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Get the UserID from ASPNET users database [Ken Cox]</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>
<asp:listbox id="ListBox1" runat="server" datasourceid="SqlDataSource1"
datatextfield="Uid"></asp:listbox></p>
<asp:sqldatasource
id="SqlDataSource1"
runat="server"
connectionstring="<%$ ConnectionStrings:ASPNETDBConnectionString %>"
selectcommand="SELECT UserId AS Uid FROM vw_aspnet_Users WHERE (UserName =
@UserName)">
<selectparameters>
<asparameter name="UserName" />
</selectparameters>
</asp:sqldatasource>
&nbsp;</div>
</form>
</body>
</html>


"Doug Batchelor" <> wrote in message
news:...
>I am using the ASP.NET membership stuff and have succesfully implemented it
>on my site. However, I would now like to be able to get the UserId which is
>stored for registered users in the aspnet_users table in ASPNETDB.MDF. The
>reason is that I would like to include this value for users who insert
>records in other tables in my database. I thought I could use the LoginName
>control to get the Username which I could then use to query the
>aspnet_users table, but I can't find a property which will give me the
>Username in the control.
>
> I would appreciate any help from the gurus out there.
>



 
Reply With Quote
 
 
 
 
Dominick Baier
Guest
Posts: n/a
 
      09-18-2006
I guess you are talking about the GUID?

You can get that from MembershipUser.ProviderUserKey

---
Dominick Baier, DevelopMentor
http://www.leastprivilege.com

> I am using the ASP.NET membership stuff and have succesfully
> implemented it on my site. However, I would now like to be able to get
> the UserId which is stored for registered users in the aspnet_users
> table in ASPNETDB.MDF. The reason is that I would like to include this
> value for users who insert records in other tables in my database. I
> thought I could use the LoginName control to get the Username which I
> could then use to query the aspnet_users table, but I can't find a
> property which will give me the Username in the control.
>
> I would appreciate any help from the gurus out there.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Forms Authentication how to get UserID ThatsIT.net.au ASP .Net 2 05-17-2008 08:03 AM
how to get user's UserId Jeff ASP .Net 1 10-14-2006 12:43 PM
How to get the network userid =?Utf-8?B?c2lsZWVzaA==?= ASP .Net 3 07-19-2004 08:09 PM
Get userID from Active Directory. Lin Ma ASP General 7 09-23-2003 03:00 AM



Advertisments