updatepermissions.ashx

来自「在编写管理信统软件中,您是否对于繁琐的多用户权限管理而头痛?需要对不同的用户设置」· ASHX 代码 · 共 68 行

ASHX
68
字号
<%@ WebHandler Language="C#" Class="UpdatePermissions" %>

using System;
using System.Web;
using System.Xml;
using System.Web.SessionState;
using System.Collections.Specialized;
using PermissionBase.Core.Service;

public class UpdatePermissions : IHttpHandler, IReadOnlySessionState
{
    private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(UpdatePermissions));

    public void ProcessRequest(HttpContext context)
    {
        context.Response.Cache.SetCacheability(HttpCacheability.NoCache);

        string sSucceed = "1";
        try
        {
            //判断访问权限。
            PermissionUtil.CheckSecurity("StaffMgr", "rights_accredit");

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(context.Request.InputStream);

            //职员ID。
            string StaffId = xmlDoc.SelectSingleNode("Permissions/StaffId").InnerText;

            //肯定授权。
            string sGrant = xmlDoc.SelectSingleNode("Permissions/Grant").InnerText;
            string[] arrGrant = null;
            if (sGrant.Length > 0)
                arrGrant = sGrant.Split('|');
            else
                arrGrant = new string[0];

            //否定授权。
            string sDeny = xmlDoc.SelectSingleNode("Permissions/Deny").InnerText;
            string[] arrDeny = null;
            if (sDeny.Length > 0)
                arrDeny = sDeny.Split('|');
            else
                arrDeny = new string[0];

            StaffSrv.UpdatePermissions(StaffId, arrGrant, arrDeny);
        }
        catch (Exception ex)
        {
            sSucceed = "-1";
            log.Error(null, ex);
        }
        finally
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write(sSucceed);
            context.Response.End();
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?