Find userId by username for anonymous users

Last post 05-28-2008 10:49 AM by satalaj. 6 replies.

Sort Posts:

  • Find userId by username for anonymous users

    05-27-2008, 11:56 AM
    • Member
      11 point Member
    • EllaW
    • Member since 05-15-2008, 2:42 PM
    • Montreal, Canada
    • Posts 79

    Hi,

     It seems I have problems at every single step in my site development!  I have a company home page. From this page, a user may input her user name and hit "Go" button to go to next page. The user maybe logged in, maybe not. The system is required to find the userID by the input user name, and write it in a cookie or so. I user a SQL to search aspnet_Users table (generated by asp)

    queryString = "SELECT [UserId] FROM [aspnet_Users] WHERE [LoweredUserName]="+userName;

    but I got null result. In management studio, I may get everything by selecting query.

     I wonder why, and if there is easy way to do with Membership Provider.

     

    Thank you!

     

    Ella

     

    EllaW
    need help and willing to help

  • Re: Find userId by username for anonymous users

    05-27-2008, 12:26 PM
    Answer
    • Contributor
      3,550 point Contributor
    • BSolveIT
    • Member since 05-11-2007, 2:20 AM
    • Northamptonshire, UK
    • Posts 607

    I'm not sure I understand what your question is, but to get the id of an anonymous user is simple enough:

            If Not User.Identity.IsAuthenticated Then
                Session("Anonymous") = Request.AnonymousID
            End If
    
     
    Cheers,
    BSolveIT

    Website Design & Search Engine Optimisation

    SEO Frequently Asked Questions

    If you get an answer to a question, please mark it as the answer. Many thanks!
  • Re: Find userId by username for anonymous users

    05-27-2008, 12:44 PM
    • Member
      11 point Member
    • EllaW
    • Member since 05-15-2008, 2:42 PM
    • Montreal, Canada
    • Posts 79

    Hi,

     Thank you for your response!

    The user has registered, and has a user name. The system need find her userID according to the user name she input, and keep tracking it in the whole session. This is a commerce site. The company recrute members to sell their products. Therefore, when a registered user comes to the site, and input her user name, she should have a welcome page with her user name, and her user id is recorded in, let's say, a cookie. But she is not logged in. If the user is not registered, she should get an error message, and page stays.

    Thanks a lot!

     

    Ella

    EllaW
    need help and willing to help

  • Re: Find userId by username for anonymous users

    05-27-2008, 1:02 PM
    Answer
    • Contributor
      3,550 point Contributor
    • BSolveIT
    • Member since 05-11-2007, 2:20 AM
    • Northamptonshire, UK
    • Posts 607

    So you are using the built in memberships and roles?

    You should use a LoginView control to achieve what your talking about.  Within the control, you create an AnonymousTemplate, and a LoggedInTemplate.  You could even use several of these controls on the page if required.

    Er... or am I still missing the point?  Sorry.

    Cheers,
    BSolveIT

    Website Design & Search Engine Optimisation

    SEO Frequently Asked Questions

    If you get an answer to a question, please mark it as the answer. Many thanks!
  • Re: Find userId by username for anonymous users

    05-27-2008, 1:27 PM
    • Member
      11 point Member
    • EllaW
    • Member since 05-15-2008, 2:42 PM
    • Montreal, Canada
    • Posts 79

    Yes, I am using Membership Provider, and I ran aspnet_regsql to merge the aspnetDB with the database I want to use. Now I have all the membership tables and the tables I need, such as Member_Info, Products, etc. I used the aspnet UserId as my memberID, not sure if that's a good idea. My loginview is placed in Master page. The question is, if a member is not logged in, how to check if his user name exists in the database.

     Thanks a lot!

    Ella

    EllaW
    need help and willing to help

  • Re: Find userId by username for anonymous users

    05-27-2008, 1:55 PM
    Answer
    • Member
      11 point Member
    • EllaW
    • Member since 05-15-2008, 2:42 PM
    • Montreal, Canada
    • Posts 79

    Ok, I tried to avoid troubles. I tested if the user exists in table aspnet_Users, then decide where to go. I think all the action should be taken after a user is logged in.

    I useed your code User.Identity.IsAuthenticated  for next step.

    Thank you!  Have a great day!

     

    Ella

    EllaW
    need help and willing to help

  • Re: Find userId by username for anonymous users

    05-28-2008, 10:49 AM
    Answer
    • Star
      9,316 point Star
    • satalaj
    • Member since 11-28-2007, 5:41 AM
    • Pune
    • Posts 1,838

    After login below code will return authenticated  user name.

    string username = HttpContext.Current.User.Identity.Name;

    Satalaj

Page 1 of 1 (7 items)