惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - 阿昆

[分享]真正的分页存储过程,借鉴了CSDN上众多力量,除BUG版,分享给大家 CommunityServer页面间关系 CommunityServer研习心得 CommunityServer皮肤主题的更换 CommunityServer实例分析 CommunityServer布局 - 阿昆 - 博客园 Community Server系列之七:快速找到需要修改的文件[技巧] Community Server系列之六:CS2中的关键词及数据结构 Community Server系列之八:CS2中的CSContext Community Server系列之四:Ajax在CS2.0中的应用1 Community Server架构:博客业务详细分析 如何在 Microsoft Visual Studio 2005 中直接Debug Community Server 2.0 的代码 与 Visual Studio 2005 Web Application Projects Community Server2.0专注细节一 邮件提醒按钮实现(上) Community Server专题附录一: 什么是Threads & Processes Community Server专题九:MemberRole之Profile Community Server专题八:MemberRole之Membership深入篇 Community Server专题八:MemberRole之Membership Community Server专题七: Job & Timer Community Server专题六:Delegates & Events
Community Server配置对网址中的www信息处理功能分析
阿昆 · 2006-06-02 · via 博客园 - 阿昆
 

国外有种习惯,比如你访问 www.****.com 网站,他会自动跳转到 ****.com
Community Server 中就提供了这种功能,而且这种功能是可选的(可以强制去掉、强制不去掉、不理睬它)。
默认情况下 Community Server 就强制去掉 www.

先说如何修改是这个功能

打开Web项目,其中的 communityserver.config 配置文件。
在这里我们可以看到下面的配置节:

<CommunityServer>
<Core ......  wwwStatus = "Remove" .... />
......
</CommunityServer>

这里可以有三个设置:
Require  
强制加 www.
Remove  
强制不加 www.  这个是默认设置 
Ignore    
忽略这个问题

只要修改成对应的设置,就自动切换了这个设置。

下面我们看它是如何实现这个功能的:

Community Server 2.0 中使用了 HttpModules 来处理这个功能:web.config中,我们可以看到 httpModules 的配置如下:

    <httpModules>
      <add name="CommunityServer" type="CommunityServer.CSHttpModule, CommunityServer.Components" />
    </httpModules>
..........

CSHttpModule 类在 CommunityServer.Components 项目的HttpModule 目录下的 CSHttpModule.cs 文件中.这个类继承了 System.Web.IHttpModule 接口

System.Web.IHttpModule 接口要求实现 初始化模块方法,即 Init 方法。
在这个类的初始化方法中,我们可以看到,我们订约了BeginRequest 事件。

public void Init(HttpApplication application)
{
 application.BeginRequest += new EventHandler(this.Application_BeginRequest);
 ......
}

在这个事件的处理函数 Application_BeginRequest ,如下,我们可以看到,先从Community Server 配置文件中读取出配置(既从communityserver.config 配置文件读取配置)
然后根据这个配置检查我该如何处理(CheckWWWStatus 函数实现)。

private void Application_BeginRequest(Object source, EventArgs e)
{
 .......
 HttpContext context = application.Context;
 .......
 CSConfiguration config = CSConfiguration.GetConfig();
 .......
 CheckWWWStatus(config,context);
 .......
}

private void CheckWWWStatus(CSConfiguration config, HttpContext context)
{
 if(config.WWWStatus == WWWStatus.Ignore)
  return;
 const string withWWW = "http://www.";
 const string noWWW = "http://";
 string rawUrl = context.Request.Url.ToString().ToLower();
 bool isWWW = rawUrl.StartsWith(withWWW);
 if(config.WWWStatus == WWWStatus.Remove && isWWW)
 {
  context.Response.Redirect(rawUrl.Replace(withWWW, noWWW));
 }
 else if(config.WWWStatus == WWWStatus.Require && !isWWW)
 {
  context.Response.Redirect(rawUrl.Replace(noWWW, withWWW));
 }
}

代码分析到此结束,Community Server 2.0 就是通过上述代码实现定制不同的 www 处理策略的。