Asp.net mvc 使用AD身份验证(非ADFS)创建MVC应用程序
我正在Visual Studio 2017中创建一个新的MVC intranet应用程序 我想使用active directory对各种控制器进行身份验证(和授权),但不使用active directory联合服务器(因为我们不使用它) 以下是我采取的步骤:Asp.net mvc 使用AD身份验证(非ADFS)创建MVC应用程序,asp.net-mvc,authentication,asp.net-mvc-5,active-directory,Asp.net Mvc,Authentication,Asp.net Mvc 5,Active Directory,我正在Visual Studio 2017中创建一个新的MVC intranet应用程序 我想使用active directory对各种控制器进行身份验证(和授权),但不使用active directory联合服务器(因为我们不使用它) 以下是我采取的步骤: 新建项目->ASP.NET Web应用程序(.NET Framework) 选择MVC 单击“更改身份验证” 选择“工作或学校帐户” 选择“本地” 现在,内部部署机构需要元数据文档URL。我知道这是ADFS的外部url。。。我们没有 如何设
提前谢谢看来我使用了错误的设置。如果要使用标准AD,请选择Windows身份验证 “工作或学校账户”似乎只针对ADF 应用程序初始化后,转到web.config 你会看到像这样的东西
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
我们需要将广告组功能添加到web.config中。完成此操作后,system.web部分应如下所示:
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
<!--NEW-->
<roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider">
<providers>
<clear />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
现在,您可以使用以下内容装饰控制器类/操作方法:
[授权(角色=@“YourDomain\Some广告组名称”)]
或通常的代码:
User.IsInRole(@“YourDomain\Some AD Group Name”))