简体   繁体   中英

asp.net web app returning IIS info instead of current user credentials

I am working with an asp.net web application using custom authentication. I wrote a quick test app to put out on our web server to make sure I could grab the necessary credentials from the user. I am trying to get the current logged in user (which I have done before) using the following line of code:

   string username=System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();

This normally returns a string in the format "domain\\user\u0026quot;. What I'm getting instead is something like this: IIS APPPOOL\\ASP.NET v4.0

I'm sure I'm missing something simple, is there a setting in IIS that needs to change? Or is there a different way to grab the username?

尝试这个:

Page.User.Identity.Name

Since you are using custom/forms authentication, it sounds like you aren't setting the IPrinicipal details after the user is authenticated.

You can follow this documentation (find the "Creating the Forms Authentication Cookie section) on how to set this code up in your app. It isn't as difficult as it looks.

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