zoukankan
html css js c++ java
基于角色的代码权限
基于角色的代码权限
演示了.NET中基于角色的安全控制,并且演示了安全控制中,对应用程序域的初始化步骤。
using
System;
using
System.Collections;
using
System.ComponentModel;
using
System.Drawing;
using
System.Windows.Forms;
public
class
WindowsForm : System.Windows.Forms.Form
{
public
static
void
Main()
{
AppDomain currentDomain
=
AppDomain.CurrentDomain;
currentDomain.SetPrincipalPolicy(
System.Security.Principal.PrincipalPolicy.WindowsPrincipal);
Application.Run(
new
WindowsForm());
}
private
Button btnOp1, btnOp2;
public
WindowsForm()
{
btnOp1
=
new
Button();
btnOp1.Text
=
"
操作A(本操作对角色无要求)
"
;
btnOp1.Size
=
new
Size(
300
,
23
);
btnOp1.Location
=
new
Point(
10
,
20
);
btnOp1.Click
+=
new
EventHandler(OnOperation1);
this
.Controls.Add(btnOp1);
btnOp2
=
new
Button();
btnOp2.Text
=
"
操作B(本操作要求本机管理员权限)
"
;
btnOp2.Size
=
new
Size(
300
,
23
);
btnOp2.Location
=
new
Point(
10
,
60
);
btnOp2.Click
+=
new
EventHandler(OnOperation2);
this
.Controls.Add(btnOp2);
this
.Size
=
new
Size(
360
,
180
);
}
private
void
OnOperation1(
object
sender, EventArgs e)
{
MessageBox.Show(
"
操作A
"
);
}
[System.Security.Permissions.PrincipalPermission(
System.Security.Permissions.SecurityAction.Demand,
Role
=
"
Administrators
"
)]
private
void
OnOperation2(
object
sender, EventArgs e)
{
MessageBox.Show(
"
操作B
"
);
}
}
查看全文
相关阅读:
gRPC中protobuff type和C# type原生标量对应表
ASP.NET MVC Json序列化时区差解决方法
多项目解决方案使用的配置文件是哪一个?
理解DDD中Factory和Repository
在Docker Desktop for Windows中Dokcer容器如何访问宿主机上的服务
ASP.NET Core日志记录基本知识
理解微信小程序小例子
[MODBUSTCP]
[pahoMQTT库的使用]
[搭建MQTT服务器及python客户端]
原文地址:https://www.cnblogs.com/hcfalan/p/504816.html
最新文章
菜单展示的递归与非递归形式实现 (go语言版)
Jaeger 简介
赫夫曼编码
ActiveMQ学习(五)---KahaDB存储原理
ActiveMQ学习(四)
ActiveMQ学习(三)
ActiveMQ学习(二)
ActiveMQ学习(一)
MQ学习技术维度
Java集合
热门文章
Java中关键字用法及作用
visual studio Code配置C++环境:
( 转载)改变人类历史的17大数学方程
关于LinQ中“from"前置的原因
(转)在Eclipse中进行C/C++开发的配置方法(20140721最新版)
豆瓣上关于<<一万小时天才理论>>一书的一个评论
window server 2012R2部署asp.net core项目应用程序池自动停止
vue项目的两种构建工具Vue CLI和Vite
npm 包管理器run命令理解
gRPC service 和client需要引用的包
Copyright © 2011-2022 走看看