技术开发 频道

使用HttpModule实现多个域名分别“绑定”到子目录


【IT168技术文档】

  先把配置文件从web.config内移出为了不让web.config变的非常臃肿,我们将配置文件从web.config内移出
假设我们的多域名绑定配置文件为“MulitDomain.config“
  将RewriterConfiguration.cs的public static RewriterConfiguration GetConfig()方法
  修改如下:
/// /// 从XML配置文件中返回重写信息 /// /// RewriterConfiguration public static RewriterConfiguration GetConfig() { RewriterConfiguration config = (RewriterConfiguration) BoovooCache.Get(CacheKey); if(config == null) { // 2005-08-18 wu meibo update the config file to SiteUrls.config // HttpContext.Current.Cache.Insert("RewriterConfig", ConfigurationSettings.GetConfig("RewriterConfig")); ///************************************************************************************ /// /// Description:将配置文件移到单独的文件内,更新以下代码,原代码(上一行)停止工作 /// ///************************************************************************************ string filePath = String.Empty; if(HttpContext.Current != null) { filePath = HttpContext.Current.Server.MapPath("~/MulitDomain.config"); } else { filePath = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "MulitDomain.config"; } XmlSerializer ser = new XmlSerializer(typeof(RewriterConfiguration)); FileStream fileReader = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader reader = new StreamReader(fileReader); config = (ser.Deserialize(reader)) as RewriterConfiguration; reader.Close(); fileReader.Close(); if (File.Exists(filePath)) { CacheDependency dep = new CacheDependency(filePath); BoovooCache.Max(CacheKey,config,dep); BoovooCache.ReSetFactor(config.CacheFactor); } } return config; }
0
相关文章