zoukankan      html  css  js  c++  java
  • Web应用程序dll获取当前程序集路径问题

    public string ConfigFile
            {
                get
                {
                    if (String.IsNullOrEmpty(_configfile))
                    {
                        //string assemblyFile = System.Reflection.Assembly.GetExecutingAssembly().Location;
                        string assemblyFile = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
                        _configfile = assemblyFile + ".config";
                    }
                    return _configfile;
                }
            }

    获得config配置信息:

    /// <summary>  
    /// 获取配置文件的属性  
    /// </summary>  
    /// <param name="key"></param>  
    /// <returns></returns>  
    public string GetConnectionStringValue(string key)
    {
        string value = string.Empty;
    
        try
        {
            //if (File.Exists(ConfigFile))
            {
                XmlDocument xml = new XmlDocument();
    
                xml.Load(ConfigFile);
    
                XmlNode xNode = xml.SelectSingleNode("//connectionStrings");
    
                XmlElement element = (XmlElement)xNode.SelectSingleNode("//add[@name='" + key + "']");
    
                value = element.GetAttribute("connectionString").ToString();
            }
        }
        catch { }
    
        return value;
    }
    慎于行,敏于思!GGGGGG
  • 相关阅读:
    web中间件常见漏洞
    心脏滴血与利用
    mimikatz提取windows密码
    Linux文本编辑器
    Linux打包(归档 )压缩命令
    linux文件和目录命令
    SSL原理
    windows server 2008 安装步骤
    渗透测试术语
    centos 7 修改yum配置
  • 原文地址:https://www.cnblogs.com/GarsonZhang/p/14413713.html
Copyright © 2011-2022 走看看