简体   繁体   中英

ASP.NET MVC, Entity Framework : Display Windows Username in _Layout

I enabled Windows authentication in the web.config file but how can I display the current Active Directory authenticated user in the _Layout.cshtml page?

Keep in mind this is not .NET Core, it is .NET 4.7.1 using Entity Framework. I'm not trying to impersonate anyone. Everywhere I look on Google turns up only antiquated .NET 2.0 posts or .NET Core answers to this question and usually involves impersonation, none of which apply to this.

Right now I just have the standard default layout page. I tried adding:

@using Microsoft.AspNet.Identity

I haven't published this to IIS yet so that's out of the picture at the moment, but will be publishing it there in the near future.

Assuming you are using IISExpress in VS. Please refer to this blog regarding how to make win auth work on IISExpress.

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