简体   繁体   中英

I have a windows authenticated HTML page hosted on IIS. How to get LoginID using C# code

I have created a sample html page and hosted it on IIS . I have enabled windows authentication . Now what I want to do is whenever I run the application, the Login ID entered by the user to be stored in database (I have already created a web service to send data to my database ). I just want know the command to store the Login ID in a variable. Kindly assist.

This should get you the username:

System.Web.HttpContext.Current.User.Identity.Name

Here is an explanation on how it works:

http://weblogs.asp.net/scottgu/Recipe_3A00_-Enabling-Windows-Authentication-within-an-Intranet-ASP.NET-Web-application

Try this

WindowsIdentity yourUserIdentity = HttpContext.Current.Request.LogonUserIdentity;

Now you can get the User name by the following property of the WindowsIdentity object yourUserIdentity.

yourUserIdentity.Name

如果您使用Windows身份验证,则可以使用它来获取LoginID

string user = Request.ServerVariables["LOGON_USER"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM