Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 使用表单身份验证ASP.NET MVC获取用户窗口_Asp.net Mvc_Iis_Web Config_Forms Authentication_Windows Authentication - Fatal编程技术网

Asp.net mvc 使用表单身份验证ASP.NET MVC获取用户窗口

Asp.net mvc 使用表单身份验证ASP.NET MVC获取用户窗口,asp.net-mvc,iis,web-config,forms-authentication,windows-authentication,Asp.net Mvc,Iis,Web Config,Forms Authentication,Windows Authentication,我正在实现一个带有表单身份验证的ASP.NET MVC项目。这个项目是部署和运行正常,但现在我需要得到当前的windows用户,但我没有得到它。我试试这个: System.Security.Principal.WindowsIdentity.GetCurrent()。名称: 但是在IIS中使用此配置返回NT AUTHORITY\NETWORK SERVICE或AUTHORITY\IUSR 匿名身份验证=已启用 模拟=已禁用 表单身份验证=已启用 Windows身份验证=已禁用 基本身份验证=已

我正在实现一个带有表单身份验证的ASP.NET MVC项目。这个项目是部署和运行正常,但现在我需要得到当前的windows用户,但我没有得到它。我试试这个:

System.Security.Principal.WindowsIdentity.GetCurrent()。名称:

但是在IIS中使用此配置返回NT AUTHORITY\NETWORK SERVICE或AUTHORITY\IUSR

  • 匿名身份验证=已启用
  • 模拟=已禁用
  • 表单身份验证=已启用
  • Windows身份验证=已禁用
  • 基本身份验证=已禁用
当我尝试时:

  • 匿名身份验证=已禁用

  • 模拟=已启用

  • 表单身份验证=已禁用

  • Windows身份验证=已启用

  • 基本身份验证=已禁用

    System.Security.Principal.WindowsIdentity.GetCurrent()。名称:Domain\User

我正确获取了当前用户窗口,但当我访问网站时,没有css样式,并且存在javascript错误

Javascript错误: 解释为样式表但使用MIME类型text/html传输的资源

我有这个网页配置:

<identity impersonate="true"/>
<authentication mode="Windows">
  <forms loginUrl="~/Account/Login" timeout="2880" />
 </authentication>

我认为这个错误是导致IIS配置失败的原因。
*所有文件夹权限:每个人都有相同的问题。。。我几乎什么都试过了,但都没用。然后我在我的网络配置中添加了这一行,它就起作用了。

还要确保您的身份验证模式设置为windows。

例如:


除非您需要以给定用户的身份访问网络资源,否则不要使用模拟。只需使用Windows身份验证,然后引用控制器的User.Identity.Name属性或HttpContext.Current.User.Identity.Name。即使您确实需要访问资源,您也应该使用WindowsImpersonationContext动态执行此操作。谢谢您的回答!我将尝试:匿名身份验证=已禁用。模拟=已禁用。表单身份验证=已禁用。Windows身份验证=已启用。基本身份验证=已禁用。我将从控制器库执行User.Identity.Name