简体   繁体   中英

How can I retrieve Logged In user in an ASP.NET web application?

I am using windows authentication in a ASP.Net Web Application and in the code-behind attempting to retrieve the logged in user name. I am using this routine WindowsIdentity.GetCurrent().Name but instead of getting the name of the user, I am getting - NT AUTHORITY\\NETWORK SERVICE. What do I need to change or are my users logging in a different way than expected?

使用this.Context.User.Identity.Name ,它将获取当前HTTPContext对象的身份: http : //msdn.microsoft.com/zh-cn/library/system.web.httpcontext.user.aspx

Add the following to your web.config:

<system.web>
    <identity impersonate="true"/>
</system.web>

This will make your web app impersonate the currently logged in user. That does have some implications. An important one is that the logged in user must have the proper rights to files, folders, databases and so on.

If you don't want that, you can use User.Identity instead of WindowsIdentity.GetCurrent() .

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