WeihanLi.AspNetMvc.AccessControlHelper
1.3.1
Prefix Reserved
See the version list below for details.
dotnet add package WeihanLi.AspNetMvc.AccessControlHelper --version 1.3.1
NuGet\Install-Package WeihanLi.AspNetMvc.AccessControlHelper -Version 1.3.1
<PackageReference Include="WeihanLi.AspNetMvc.AccessControlHelper" Version="1.3.1" />
paket add WeihanLi.AspNetMvc.AccessControlHelper --version 1.3.1
#r "nuget: WeihanLi.AspNetMvc.AccessControlHelper, 1.3.1"
// Install WeihanLi.AspNetMvc.AccessControlHelper as a Cake Addin #addin nuget:?package=WeihanLi.AspNetMvc.AccessControlHelper&version=1.3.1 // Install WeihanLi.AspNetMvc.AccessControlHelper as a Cake Tool #tool nuget:?package=WeihanLi.AspNetMvc.AccessControlHelper&version=1.3.1
实现自己的权限控制显示策略类
- 实现页面元素显示策略接口
IControlAccessStrategy
- 实现
Action
访问显示策略接口IActionAccessStrategy
示例代码:
ASP.NET Mvc
ASP.NET Core
- 实现页面元素显示策略接口
程序启动时注册自己的显示策略
- asp.net mvc
可基于Autofac实现的依赖注入,在 autofac 的 Ioc Container中注册显示策略,并返回一个可以从Ioc Container中获取对象的委托或者实现
IServiceProvider
接口的对象,参考 Asp.Net 注册示例//autofac ContainerBuilder var builder = new ContainerBuilder(); // etc... // register accesss control builder.RegisterType<ActionAccessStrategy>().As<IActionAccessStrategy>(); builder.RegisterType<ControlAccessStrategy>().As<IControlAccessStrategy>(); var container = builder.Build(); // Important AccessControlHelper.RegisterAccessControlHelper<ActionAccessStrategy, ControlAccessStrategy>(type => container.Resolve(type));
- asp.net core
在
Startup
文件中注册显示策略,参考 Asp.Net Core 注册示例// Configure app.UseAccessControlHelper(); // ConfigureServices services.AddAccessControlHelper<ActionAccessStrategy, ControlAccessStrategy>();
控制
Action
的方法权限通过
AccessControl
和NoAccessControl
Filter 来控制Action
的访问权限,如果Action上定义了NoAccessControl
可以忽略上级定义的AccessControl
,另外可以设置 Action 对应的AccessKey
使用示例:
[NoAccessControl] public IActionResult Index() { return View(); } [AccessControl] public IActionResult About() { ViewData["Message"] = "Your application description page."; return View(); } [AccessControl(AccessKey = "Contact")] public IActionResult Contact() { ViewData["Message"] = "Your contact page."; return View(); }
控制页面元素的显示
为了使用比较方便,建议在页面上导入命名空间,具体方法如下,详见 Samples:
通过
HtmlHelper
扩展方法来实现权限控制SparkContainer
使用@using(Html.SparkContainer("div",new { @class="container",custom-attribute = "abcd" })) { @Html.Raw("1234") } @using (Html.SparkContainer("span",new { @class = "custom_p111" }, "F7A17FF9-3371-4667-B78E-BD11691CA852")) { @:12344 }
没有权限访问就不会渲染到页面上,有权限访问的时候渲染得到的 Html 如下:
<div class="container" custom-attribute="abcd">1234</div> <span class="custome_p111">12344</span>
SparkLink
@Html.SparkLink("Learn about me »", "http://weihanli.xyz",new { @class = "btn btn-default" })
有权限访问时渲染出来的 html 如下:
<a class="btn btn-default" href="http://weihanli.xyz">Learn about me »</a>
SparkButton
@Html.SparkButton("12234", new { @class= "btn btn-primary" })
有权限访问时渲染出来的 html 如下:
<button class="btn btn-primary" type="button">12234</button>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5
- Microsoft.AspNet.Mvc (>= 3.0.20105.1)
-
.NETStandard 2.0
- Microsoft.AspNetCore.Mvc (>= 2.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.13.0 | 1,185 | 10/19/2020 |
1.12.0 | 1,231 | 1/27/2020 |
1.11.0 | 706 | 1/19/2020 |
1.10.0 | 833 | 12/8/2019 |
1.10.0-preview-20191204-022215 | 448 | 12/4/2019 |
1.9.2 | 801 | 10/20/2019 |
1.9.1 | 754 | 10/15/2019 |
1.9.0 | 828 | 9/24/2019 |
1.8.2 | 818 | 9/3/2019 |
1.8.0 | 1,184 | 6/21/2019 |
1.6.0 | 1,155 | 2/21/2019 |
1.5.0 | 926 | 11/20/2018 |
1.4.0 | 983 | 10/10/2018 |
1.3.1 | 1,203 | 12/9/2017 |
1.1.0 | 1,239 | 10/16/2017 |
remove reference for WeihanLi.Common and update IActionAccessStrategy interface,optimize code