Visual Studio 2015 vNext和Windows身份验证

时间:2015-03-24 16:44:51

标签: c# asp.net iis windows-authentication visual-studio-2015

如何配置项目以使用Windows身份验证?既然没有web.config文件,我看不出怎么做。

我在启动时看到app.UseIdentity(),但不知道如何在IIS Express中使用Windows Auth。当我尝试在IIS(Windows 7,IIS 7.5)中创建项目时,似乎没有.NET 4.6 / 4.5应用程序池我尝试使用.NET 4.0但出现错误:

  

无法确定要运行的适当版本的运行时。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=517742

当然,该链接并未向我提供信息,而是http://www.asp.net/

3 个答案:

答案 0 :(得分:6)

在使用VS2015进行调试时对我有用:

打开IIS Express配置文件:%userprofile%\Documents\IISExpress\config\applicationhost.config

有一条线说:
<windowsAuthentication enabled="false">

将其更改为:
<windowsAuthentication enabled="true">

然后我加入了我的Web.conf:

<authentication mode="Windows">
</authentication>
<authorization>
</authorization>

然后我可以通过以下方式拉出Windows用户名:
Request.LogonUserIdentity.Name

答案 1 :(得分:1)

转到网站项目属性 - &gt;调试 - &gt; IIS Express设置部分和那里取消选中启用匿名身份验证和选中启用Windows身份验证。

用户(在控制器中)将加载本地域数据。

http://screencast.com/t/GecnmVnXHC

修改
我们必须启用匿名身份验证,否则CORS预检请求将失败(401)

答案 2 :(得分:-2)

IISExpress也有一个配置文件。请参阅此处的指南:请参阅Using Windows Authentication with IISExpress