简体   繁体   English

ASP.NET MVC,实体框架:在_Layout中显示Windows用户名

[英]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? 我在web.config文件中启用了Windows身份验证,但是如何在_Layout.cshtml页面中显示当前经过Active Directory身份验证的用户?

Keep in mind this is not .NET Core, it is .NET 4.7.1 using Entity Framework. 请记住,这不是.NET Core,而是使用Entity Framework的.NET 4.7.1。 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. 在我所看到的所有地方,Google只会出现过时的.NET 2.0帖子或.NET Core这个问题的答案,并且通常涉及假冒,但都不适用于该假冒。

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. 我尚未将其发布到IIS,因此目前尚无法解决,但将在不久的将来发布到IIS。

Assuming you are using IISExpress in VS. 假设您在VS中使用IISExpress。 Please refer to this blog regarding how to make win auth work on IISExpress. 请参阅此博客 ,以了解如何使IISExpress上的Win Auth工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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