Asp.net-Mvc-4
使用活動目錄角色提供程序 MVC4 進行授權
我正在建構一個 MVC4 應用程序供公司環境內部使用。我使用 Windows 身份驗證,效果很好,但是我在使用 Active Directory 組作為授權角色時遇到了麻煩。
我的 Web.config 如下所示:
<authentication mode="Windows" /> <roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"> <providers> <clear /> <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" /> </providers> </roleManager> <authorization> <deny users="?" /> </authorization>當我使用使用者授權時,它工作正常:
[Authorize(Users = @"DOMAIN\User1, DOMAIN\User2")] public ActionResult Create() { return View(); }但是當我使用角色時,它只是不允許該組中的使用者訪問此操作:
[Authorize(Roles = @"Domain\Group")] public ActionResult Create() { return View(); }我還嘗試在其他回復中閱讀時指定沒有域的組,但沒有運氣……我想我在 Web.config 中遺漏了一些東西,但我不確定是什麼……
我避免使用自定義角色提供程序,因為 MVC4 應該在沒有自定義角色提供程序的情況下實現這一點(或者至少這是我的想法)
誰能幫我這個?
提前致謝!
我發現這是問題所在。在閱讀了有關 machine.config的一些資訊後,我檢查了我是否已經應用了正確的配置。
最後我讓它像這樣工作:
[Authorize(Roles = "Domain\\Group")] public ActionResult Create() { return View(); }問題是我輸入組的方式。
我希望這可以幫助其他人。