看來我使用了錯誤的設置。如果您想使用標準AD,請選擇Windows身份驗證。
「工作或學校帳戶」似乎只適用於ADFS。
一旦您的應用程序初始化,請轉至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>
我們需要在AD組的功能添加到我們的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>
現在,您可以用下面的來裝飾你的控制器類/ action方法:
[授權(角色= @「您的域\一些廣告組名稱 「)]
或通常的代碼:
User.IsInRole(@」 您的域\一些廣告組名稱「))