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

前提是你 提交于 2019-12-18 13:37:43

问题


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 way to automatically get the username of whoever is accessing the page based on the name used to either log into the local machine or that used for the VPN?


回答1:


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.




回答2:


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?



回答3:


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

User.Identity.Name



回答4:


You can use

Page.User.Identity.Name



回答5:


If the authentication is windows, this should help:

IIdentity WinId= HttpContext.Current.User.Identity;
WindowsIdentity wi = (WindowsIdentity)WinId;


来源:https://stackoverflow.com/questions/761016/get-the-username-of-the-user-accessing-asp-net-intranet-page-within-local-networ

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!