国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - ASP.NET教程 - ASP.NET下使用xml反序列化、緩存依賴實現個性化配置文件的實時生效

ASP.NET下使用xml反序列化、緩存依賴實現個性化配置文件的實時生效

2020-04-18 14:17輝色天空 ASP.NET教程

本文主要介紹了ASP.NET下使用xml反序列化、緩存依賴實現個性化配置文件的實時生效的方法。具有一定的參考價值,下面跟著小編一起來看下吧

因為一些配置屬性比較多,存在多組屬性,因此結合xml解析、緩存技術,實現配置文化的自動解析、存入緩存、緩存依賴實時更新配置內容。

配置文件反序列化存入緩存的核心方法:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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;
 }

上面自動獲取rootPath的方法:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/// <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;
}

Settings實體類的定義,要注意,這里的實體類要和settings配置文件對應,否則反序列化會出錯:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[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
}

settings.config的內容實例

?
1
2
3
4
5
6
7
8
9
10
11
<?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>

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持服務器之家!

原文鏈接:http://huisky.com/blog/17011922322264

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲色图综合 | 亚洲国产精品成人精品 | 视频一区 中文字幕 | 久久国产精品久久久久久 | 久久久精品天堂 | 日本不卡高字幕在线2019 | 国产一区二区免费 | 天天摸天天干 | 99热精品在线 | 国产高清精品在线 | 日本高清无卡码一区二区久久 | 国产三区av| 国产精品一区二区不卡 | 日韩成人一区二区 | 天天综合久久 | 亚洲激情综合 | 日本一区不卡 | 午夜视频在线播放 | 国产一区成人 | 国产精品福利视频 | 国产精品视频久久 | 亚洲成人av免费看 | 18.wxww.成人性视频高清 | 国产精品a久久久久 | 一级黄色录像在线观看 | 97国产超碰| 欧美日韩综合视频 | 国产v日产∨综合v精品视频 | 欧美一级黄 | jizz国产 | 国产高清在线精品一区二区三区 | 羞羞视频免费观看 | 一级欧美 | 婷婷久久一区 | 国产福利视频在线观看 | 日韩国产 | 精品香蕉一区二区三区 | 国产在线观看一区 | 精品无码三级在线观看视频 | 欧美色视频在线观看 | 亚洲精品一区二区 |