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(30023);
            btnOp1.Location 
    = new Point(1020);
            btnOp1.Click 
    += new EventHandler(OnOperation1);
            
    this.Controls.Add(btnOp1);
            
            btnOp2 
    = new Button();
            btnOp2.Text 
    = "操作B(本操作要求本机管理员权限)";
            btnOp2.Size 
    = new Size(30023);
            btnOp2.Location 
    = new Point(1060);
            btnOp2.Click 
    += new EventHandler(OnOperation2);
            
    this.Controls.Add(btnOp2);
            
            
    this.Size = new Size(360180);
        }

        
        
    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");
        }
        
    }

  • 相关阅读:
    分布式解决方案的收集
    一天带你入门到放弃vue.js(三)
    一天带你入门到放弃vue.js(二)
    一天带你入门到放弃vue.js(一)
    JDK配置环境变量不成功的原因
    蚂蚁课堂(每特学院)-2期
    Java 使用blob对H5视频播放进行加密《java视频加密》
    Java 实现视频下载功能
    高并发与高可用实战之基础知识大型网站架构特征(一)
    Java线程池实现原理之自定义线程池(一)
  • 原文地址:https://www.cnblogs.com/hcfalan/p/504816.html
Copyright © 2011-2022 走看看