webconfigtool.cs

来自「通用权限管理平台」· CS 代码 · 共 42 行

CS
42
字号
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Web;

namespace MemberServerBLL
{
    public class WebConfigTool
    {
        public static void SetValue(string key, string strValue, string FileName)
        {
            string XPath = "/appSettings/add[@key='?']";
            XmlDocument membershipConfig = new XmlDocument();

            membershipConfig.Load((HttpContext.Current.Server.MapPath(FileName)));
            XmlNode addKey = membershipConfig.SelectSingleNode((XPath.Replace("?", key)));
            if (addKey == null)
            {
                throw new ArgumentException("没有找到<add key='" + key + "' value=.../>的配置节");
            }
            addKey.Attributes["value"].InnerText = strValue;
            membershipConfig.Save((HttpContext.Current.Server.MapPath(FileName)));
        }

        public static string GetValue(string key, string FileName)
        {
            string XPath = "/appSettings/add[@key='?']";
            XmlDocument membershipConfig = new XmlDocument();

            membershipConfig.Load((HttpContext.Current.Server.MapPath(FileName)));
            XmlNode addKey = membershipConfig.SelectSingleNode((XPath.Replace("?", key)));
            if (addKey == null)
            {
                throw new ArgumentException("没有找到<add key='" + key + "' value=.../>的配置节");
            }
            return addKey.Attributes["value"].InnerText;

        }
    }
}

⌨️ 快捷键说明

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