Windows身份验证-获取当前用户名 [英] Windows Authentication - Getting current user name
问题描述
在我的MVC应用程序中,如果当前登录用户是x人,我想在cshtml文件中呈现一个表.我正在使用Windows身份验证,并且已在web.config文件中进行了以下更改.
In my MVC application I want to render a table in a cshtml file, if the current log in user is some x person. I am using windows authentication and I have made the following changes in web.config file.
<authentication mode="Windows">
</authentication>
在我的控制器中,当我尝试访问当前用户名时,我没有任何用户名.我正在尝试以下操作:
And in my controller when I am trying to access the current user name I am not getting any user name. I am trying the following:
ViewBag.LogInUserName = Request.RequestContext.HttpContext.User.Identity.Name;
以上这行之前曾起作用.但是我不知道现在出了什么问题.另外,我现在也将应用程序托管在IIS上.
This above line was working before. But I don't know whats wrong now. Also I have hosted my application on IIS now.
推荐答案
看看该Web项目的属性,尤其是:
Take a look at the web project's properties, in particular:
- 匿名身份验证-设置为已禁用"
- Windows身份验证-设置为启用"
默认情况下,这些设置与您可能要查找的相反.
By default these are set to the opposite of what you're probably looking for.
(图片来自 MSDN )
这篇关于Windows身份验证-获取当前用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!