网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 大学论文导航 设计下载 最新论文 下载排行 原创论文 论文源代码
返回网学首页
网学联系
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 编程文档 > ASP.net > 正文

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

来源:http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/12

作者:活靶子 发表于:AspxBoy.Com && im286.com && Cnblogs.com

目前虚拟主机商提供将多个域名绑定到站点根目录,但是不提供类似cpanel那样可以将域名绑定到站点的子目录。
而当你手上有多个域名,网站空间和流量又有闲置的时候,是很希望
将这些资源利用起来,而且要做到降低做站的成本。而网络上流传的多域名绑到子目录多为判断HTTP_HOST再使用Asp的Response.Redirect或者php的header方法重订向到子目录去。这种方法在地址的请求上发生了变化,大家都知道Redirect的定向是很不友好的,在服务器端控制自动跳转会令访问者感到不安。
所以我需要的是对这个域名下面的所有请求都转接到对应的子目录里去
比如

http://www.xaradio.com/default.aspx
实际访问的是http://www.3pub.com/xaradio/default.aspx

http://www.xaradio.com/album.aspx?id=722
实际访问的是http://www.3pub.com/xaradio/album.aspx?id=722

http://www.xaradio.com/*.aspx
实际要访问到http://www.3pub.com/xaradio/*.aspx

而绑定到该站点根目录的其他域名和地址仍然不受影响
如: http://www.3pub.com/ 和http://3pub.com/
 http://www.3pub.com/default.aspx和http://3pub.com/default.aspx


http://www.aspxboy.com/484/default.aspx该文章详细的描述了在Asp.Net中使用HttpModule和HttpHander来重写Url,读懂他特别是http://www.aspxboy.com/484/archive.aspx#ekaa将是我们下面工作的前提朋友们可以下载该文章附带的代码研究。

如果您对HttpModule的编成非常熟悉那么可以向下进行了

一。 先把配置文件从web.config内移出为了不让web.config变的非常臃肿,我们将配置文件从web.config内移出
假设我们的多域名绑定配置文件为“MulitDomain.config“
将RewriterConfiguration.cs的public static RewriterConfiguration GetConfig()方法
修改如下:

/// /// 从XML配置文件中返回重写信息/// /// RewriterConfigurationpublic 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"));///************************************************************************************///  ///  Author:活靶子,huobazi/// Date:2005-08-18//////  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;} 
二。做一些修补
RewriterModule.cs内
public virtual void	 
			
  • 下一篇资讯: session和viewstate的比较
  • 网学推荐

    免费论文

    原创论文

    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号