getting logged in user name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karthi84
    Contributor
    • Dec 2006
    • 270

    getting logged in user name

    Hi,
    I need to get the user name of the current logged in person (remote user), who is accessing the site. Is there any way to get the logged in username.

    Thanks & Regards
    Karthi
  • liawcv
    New Member
    • Jan 2009
    • 33

    #2
    If you are implementing forms-based authentication with correct authentication and authorization configuration, you should be able to get the current logged in person's username from the following methods:

    (1) By using the LoginName control.

    (2) Accessing to User.Identity.N ame property.

    Comment

    • karthi84
      Contributor
      • Dec 2006
      • 270

      #3
      Hi Liawcv,
      My requirement is different. I dont have a login page for my application. My application is an intranet application in which restrictions are to be made based on the username. i need to fetch the windows login user name of the client machine and cross map it to a roles table and display the menus based on his roles.
      So is there any possible way to get the client machines username.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        You need to configure your web application to use windows authentication.

        Once you've done this you will be able to access the WindowsPrincipa l Object contains an WindowsIdentity Object that represents the Windows user. The WindowsPrincipa l object contains permission information about the user's account including what groups the are in etc; whereas the WindowsIdentity object contains everything about the Windows user (including the user name)

        The WindowsPrincipa l object automatically created when the user sucessfully logs into your ASP.NET website using their windows account. This happens before any of your website code is executed. The WindowsPrincipa l object is stored in the HttpContext.Use r property. You can access the HttpContext.Use r in any page in your website...you can also access it in any custom classes or objects that you have created.

        Once you have the WindowsPrincipa l, you can then access the WindowsIdentity object that represents the user through the WindowsPrincipa l.Identity property.

        Then you can retrieve the UserName by accessing the WindowsIdentity 's Name Property.


        I think I have covered the basics.

        Please research the topic of Windows Authentication because there is a lot more that you should know about Windows Authentication. (Like the User.IsInRole method that is available through the WindowsPrincipa l....you can set up proper windows groups to assign Windows users to in order to determine which resources they are allowed to access in your website)

        Happy coding!

        -Frinny

        Comment

        Working...