public Class.Settings GetSettings()
{
if (HttpRuntime.Cache["settings"] != null)
return (Class.Settings)HttpRuntime.Cache["settings"];
string rootPath = GetPath();
#region rootPath
if (rootPath == "")
{
log.Write(MsgType.Fatal, "配置文件根目录rootPath为空");
return null;
}
else
{
if (!rootPath.EndsWith("\\"))
rootPath += "\\";
rootPath = rootPath + "settings\\settings.config";
}
#endregion
if (!File.Exists(rootPath))
{
log.Write(MsgType.Fatal, "配置文件根目录rootPath为空");
return null;
}
string content = File.ReadAllText(rootPath, Encoding.Default);
Class.Settings model = PublicMethod.XmlSerialize.DeserializeXML<Class.Settings>(content);
log.Write(MsgType.Information, "读取配置文件");
CacheDependency cd = new CacheDependency(rootPath);
HttpRuntime.Cache.Add("settings", model, cd, DateTime.Now.AddMinutes(5), TimeSpan.Zero, CacheItemPriority.High, null);
return model;
}
/// <summary>
/// 取当前根目录的方法
/// </summary>
private static string GetPath()
{
string rootPath = "";
System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();
//WebDev.WebServer visual studio web server
//xxx.vhost Winform
//w3wp IIS7
//aspnet_wp IIS6
//iisexpress vs2013
string processName = p.ProcessName.ToLower();
if (processName == "aspnet_wp" || processName == "w3wp" || processName == "webdev.webserver" || processName == "iisexpress")
{
if (System.Web.HttpContext.Current != null)
rootPath = System.Web.HttpContext.Current.Server.MapPath("~/");
else //当控件在定时器的触发程序中使用时就为空
{
rootPath = System.AppDomain.CurrentDomain.BaseDirectory;
}
}
return rootPath;
}
[XmlRoot(Namespace = "", IsNullable = false, ElementName = "settings")]
public class Settings
{
#region 属性
[XmlElement("logger")]
public LoggerConfig logger { get; set; }
#endregion
#region 子类
[XmlType(TypeName = "logger")]
public class LoggerConfig
{
public string loglevel { get; set; }
public string savepath { get; set; }
}
#endregion
}
<?xml version='1.0' encoding='utf-8'?> <settings> <logger> <loglevel>0</loglevel> <savepath>d:\log</savepath> </logger> <queryurl>http://11.56.254.234:88/shashachaxunserver/shashachaxun</queryurl> <receiveurl>http://172.16.1.131:88/ThirdPay/ChinaUMS/xml.aspx</receiveurl> <turnurl>http://172.16.1.131:88/ThirdPay/ChinaUMS/query.aspx</turnurl> </chinaums> </settings>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有