How to get the USERID

Discussion in 'ASP .Net Security' started by Doug Batchelor, Sep 17, 2006.

  1. 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.
     
    Doug Batchelor, Sep 17, 2006
    #1
    1. Advertising

  2. 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>
    <asp:parameter 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.
    >
     
    Ken Cox [Microsoft MVP], Sep 18, 2006
    #2
    1. Advertising

  3. 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.
    >
     
    Dominick Baier, Sep 18, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?c2lsZWVzaA==?=

    How to get the network userid

    =?Utf-8?B?c2lsZWVzaA==?=, Jul 19, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    4,394
    bruce barker
    Jul 19, 2004
  2. Jeff

    how to get user's UserId

    Jeff, Oct 14, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    683
    Jon Paal
    Oct 14, 2006
  3. ThatsIT.net.au

    Forms Authentication how to get UserID

    ThatsIT.net.au, May 17, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    597
  4. Lin Ma

    Get userID from Active Directory.

    Lin Ma, Sep 22, 2003, in forum: ASP General
    Replies:
    7
    Views:
    584
  5. Kam
    Replies:
    4
    Views:
    149
    Bob Barrows [MVP]
    Sep 4, 2006
Loading...

Share This Page