Get the username of the user accessing ASP.NET intranet page within local network

前端 未结 5 749
遇见更好的自我
遇见更好的自我 2021-01-01 05:25

We have an ASP.NET intranet site, available to users who are either physically at and logged into a local machine or else to users who connect remotely via VPN. Is there a

相关标签:
5条回答
  • 2021-01-01 06:03

    You can use

    Page.User.Identity.Name
    
    0 讨论(0)
  • 2021-01-01 06:05

    This is possible if you're using Windows Authentication in your pages.

    You can use either Page.User.Identity.Name or the more complete System.Web.HttpContext.Current.User.Identity.Name.

    Read more about it here:

    Enabling Windows Authentication within an Intranet ASP.NET Web Application

    If you are, however, using Forms Authentication, you'll have to keep track of the current user yourself, the most common method of which will be by storing their login name in a Session variable.

    0 讨论(0)
  • 2021-01-01 06:07

    If the authentication is setup to do Integrated Windows authentication then you should be able to get it by accessing

    User.Identity.Name

    0 讨论(0)
  • 2021-01-01 06:12

    Get the User information as follows:

    User.Identity.Name \\ Get the User name
    User.Identity.AuthenticationType \\ What is the Authentication type
    User.Identity.IsAuthenticated \\ Is he authenticated?
    User.IsInRole("Administrators") \\ Is he administrator?
    
    0 讨论(0)
  • 2021-01-01 06:18

    If the authentication is windows, this should help:

    IIdentity WinId= HttpContext.Current.User.Identity;
    WindowsIdentity wi = (WindowsIdentity)WinId;
    
    0 讨论(0)
提交回复
热议问题