今天是:
设为首页 收藏本站 联系站长

◆你现在的位置是:首页 >> 程序开发 >> asp.net >> 正文
站内搜索:

 

基于角色的代码权限

2008-03-28 阅读: 出处: 作者: 编辑: 
 

演示了.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");
    }   
}

上一条新闻:
下一条新闻:

【郑重声明】渐飞IT人阵地刊载此文不代表同意其说法或描述,仅为提供更多信息,也不构成任何投资或其他建议。转载需经渐飞IT人阵地同意并注明出处。本网站有部分文章是由网友自由上传。对于此类文章本站仅提供交流平台,不为其版权负责。如果您发现本网站上有侵犯您的知识产权的文章,请联系我们。
相关资讯
进入渐飞IT人阵地
姓名: 发言时务必尊重网上道德与相关法律法规
 

热点推荐排行榜

网站模板欣赏

最新软件下载