asp.net-mvc – 如何在ASP.NET MVC 4中使用域组作为具有流畅安全
发布时间:2020-12-16 04:27:13 所属栏目:asp.Net 来源:网络整理
导读:在我的ASP.NET MVC 4应用程序中,我使用Intranet模板来实现 Windows身份验证.我也在使用Fluent Security. 开箱即用,我可以使用下面显示的注释来限制对特定域组或域用户的控制器方法的访问. [Authorize(Roles=@"DomainGroupName")]public ActionResult Index(
在我的ASP.NET MVC 4应用程序中,我使用Intranet模板来实现
Windows身份验证.我也在使用Fluent Security.
开箱即用,我可以使用下面显示的注释来限制对特定域组或域用户的控制器方法的访问. [Authorize(Roles=@"DomainGroupName")] public ActionResult Index() { ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; return View(); } [Authorize(Users=@"DomainUserName")] public ActionResult About() { ViewBag.Message = "Your app description page."; return View(); } 如何使用Fluent Security将这两种方法限制为同一域组和域用户?如果这更容易,我对用户比对用户更感兴趣.我是否需要构建自定义策略?如果是这样,我不太确定如何检查经过身份验证的用户是否在域组中以返回Fluent Security的正确角色? 我已经完成了FluentSecurity的入门,所以我知道如何实现FluentSecurity的基础知识,我只是不确定如何使用域组作为角色. 谢谢! 解决方法
我可能已经找到了一种将域组用于角色的方法.我已从Fluent Security入门页面调整了扩展示例.
在Global.asax.cs中: SecurityConfigurator.Configure(configuration => { // Let Fluent Security know how to get the authentication status of the current user configuration.GetAuthenticationStatusFrom(() => HttpContext.Current.User.Identity.IsAuthenticated); // Let Fluent Security know how to get the roles for the current user configuration.GetRolesFrom(System.Web.Security.Roles.GetRolesForUser); // This is where you set up the policies you want Fluent Security to enforce configuration.For<HomeController>().Ignore(); configuration.For<AccountController>().DenyAuthenticatedAccess(); configuration.For<AccountController>(x => x.ChangePassword()).DenyAnonymousAccess(); configuration.For<AccountController>(x => x.LogOff()).DenyAnonymousAccess(); configuration.For<BlogController>(x => x.Index()).Ignore(); configuration.For<BlogController>(x => x.AddPost()).RequireRole(@"DomainWriters"); configuration.For<BlogController>(x => x.AddComment()).DenyAnonymousAccess(); configuration.For<BlogController>(x => x.DeleteComments()).RequireRole(@"DomainWriters"); configuration.For<BlogController>(x => x.PublishPosts()).RequireRole(@"DomainOwners"); // To authorize the Home Controller Index Action as in my original question configuration.For<HomeController>(c => c.Index()).RequireRole(@"DomainGroupName"); }); GlobalFilters.Filters.Add(new HandleSecurityAttribute(),0); 在Web.config中: <authentication mode="Windows" /> <authorization> <deny users="?" /> </authorization> <roleManager defaultProvider="WindowsProvider" enabled="true" cacheRolesInCookie="false"> <providers> <add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider" /> </providers> </roleManager> 我还没有找到一种授权单个用户的方法,但我们都知道通常最好使用组. 有没有更好的方法来做到这一点? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Asp.net中的Session和Cookie
- asp.net-mvc – 将WebForm视图引擎标记转换为Razor视图引擎
- asp.net-mvc – IIS 7与IIS Express的路由错误,生成HTTP 40
- asp.net-mvc – 过滤Kendo UI MVC Grid时的自定义谓词构建
- asp.net-mvc – 防止JsonResult自动格式化日期
- asp.net – NewRelic – 如何忽略Web应用程序的一部分
- asp.net-mvc – MVC捆绑:错误403
- asp.net-mvc – 使用sqlserver express时不创建数据库的Ent
- asp.net-core – 未配置身份验证处理程序来处理该方案:Mic
- asp.net – 如何在aspx页面中显示pdf?
推荐文章
站长推荐
- asp.net – 为什么DropDownList.SelectedValue依
- 在Asp.net Web API中捕获404错误
- asp.net-mvc-4 – 在MVC中的App_Start()文件夹中
- 设计模式 – 为什么在绿地ASP.Net MVC应用程序中
- asp.net – 安装.net 4.5自定义表单身份验证后中
- 缺少“ASP.NET核心Web应用程序(.NET Framework)”
- 一步步开发自己的博客 番外篇(8、第三方登录及问
- 单元测试Raven和ASP.NET成员资格
- ASP.NET Web API控制器专用串行器
- asp.net-mvc-3 – 带有附加HTML的MVC3 Html.Begi
热点阅读