Results 1 to 3 of 3

Thread: FormsAuthentication with my own DB - get logged on user

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    FormsAuthentication with my own DB - get logged on user

    Hi,

    First of all, I'm very new to ASP.NET (though not .NET in general), so my apologies if something is obvious... It's not for me


    I am trying to build a simple login system in my website. I did some searching and found that there are quite a few 'templates' (such as the Login controls) that Visual Studio provides for you. However, by default those need a MS SQL Server database. This is a problem for me because
    1. I don't have a MS SQL database,
    2. My webspace provider does support it, but only for an additional fee, and I feel paying an additional fee just for a simple login system is... no.
    3. I'd like to keep it all in my existing (Access) database.


    I came across this website which shows me how to handle the login system with an Access database.
    As far as I can tell all I need is the username and then I can get all the built-in login controls and such working.


    So, I implemented this, and it seems to work fine. I can login using the Login control, I can display or hide content whether or not the user is logged in using the LoginView control, I can display a Login / Logout link, etc.

    The only thing I cannot seem to do is get the name of the currently logged in user (if any). All I need is the name, I can get the rest via the database manually that's no problem.


    There is the LoginName control which displays that name to me, but I cannot figure out how to retrieve it in code.

    I did found the Membership.GetUser() method, but it doesn't seem to work (because I'm using my own Access database? I dunno), it returns Nothing even if a user is logged in (the LoginName control shows the name).

    How can I do this..? Thanks!

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: FormsAuthentication with my own DB - get logged on user

    Hey Nick,

    Try this:

    Code:
    System.Web.HttpContext.Current.User.Identity.Name
    More info here:

    http://msdn.microsoft.com/en-us/libr...tity.name.aspx

    and here:

    http://msdn.microsoft.com/en-us/libr...text.user.aspx

    Hope that helps!

    Gary

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: FormsAuthentication with my own DB - get logged on user

    Awesome, it worked just fine I'd expected it to be harder. I must say I can't really get my head around the user/login/security stuff at the moment (maybe cause it's getting late..). It seems there are like 20 different ways to authenticate users and you can even mix all of them up :/ Maybe it's just me lol but I can't make much sense of it yet

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width