asp.net-mvc – 如何在ASP.NET MVC 4中使用域组作为具有流畅安全性的角色?
发布时间:2020-05-24 11:18:49 所属栏目:asp.Net 来源:互联网
导读:在我的ASP.NET MVC 4应用程序中,我使用Intranet模板来实现 Windows身份验证.我也在使用Fluent Security. 开箱即用,我可以使用下面显示的注释来限制对特定域组或域用户的控制器方法的访问. [Authorize(Roles=@DomainGroupName)]public ActionResult Index(){ V
|
在我的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>
我还没有找到一种授权单个用户的方法,但我们都知道通常最好使用组. 有没有更好的方法来做到这一点? (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- System.Net.ServicePointManager.DefaultConnectionLimit =
- asp.net-mvc-3 – 用于创建自定义成员资格提供程序的示例代
- asp.net – 为什么几次调用HttpApplication构造函数
- asp.net-mvc – 如何在运行时之前编译cshtml
- asp.net – 如何在一个web项目正在调试的同时运行一个测试?
- asp.net-mvc – 如何更改ASP.NET MVC中的默认验证错误消息?
- asp.net-mvc-3 – 在MVC3中设置所选选项
- asp.net – 可以使用URI模板来匹配URI到路由吗?
- asp.net – MVC 3在IEnumerable模型视图中编辑数据
- asp.net-mvc – MVC3 AntiForgeryToken打破了Ajax登录
推荐文章
站长推荐
- asp.net – 在没有Global.asax的情况下处理应用程
- ASP.NET MVC – 如何从局部视图中获取当前操作?
- asp.net-mvc – ASP.NET MVC – 用于ICollection
- asp.net-mvc-3 – 使用Html.EditorFor为新记录创
- asp.net-mvc-3 – 如何修复此MVC网站错误:无法加
- asp.net-mvc – 在ASP.NET MVC中指定只读会话
- asp-classic – VBScript条件短路解决方法
- asp.net – IIS 7.5无法打开处理程序映射?
- asp-classic – 经典asp中的串联字符串
- asp.net – Visual Studio 2015 RC中的界面上的错
热点阅读
