zoukankan      html  css  js  c++  java
  • asp.net下通过泛解析和伪静态实现二级域名的实现方法

    在net中微软已经为我们留下了接口,让我们为所欲为了。

    首先我们可以通过一张图大概了解下.net的生命周期。 

    从 上图可以看出来,针对每个不同用户的请求,服务器都会创建一个新的HttpContext实例直到请求结束,服务器销毁这个实例。而 Ihttpcontext是httpcontext对外公开的接口,它包含了2个方法:dispose()和Init(HttpApplication context),我们可以实现Ihttpcontext从而达到httpcontext。 
    关键代码: 

    复制代码代码如下:

    HttpApplication app = (HttpApplication)sender; 
    HttpContext context = app.Context; 
    string url = context.Request.Url.AbsoluteUri; //完整url 
    string turl = url.Split('.')[0]; 
    string surl = turl.ToLower().Replace("http://", ""); 
    StringBuilder strb = new StringBuilder(); 
    strb.Append(url); 
    strb.Append(surl); 


    app.Context.RewritePath(path, string.Empty, strb.ToString().Split('?')[1]); 
    在web.config里配置下: 
    <system.web>里添加如下代码。 
    <httpModules> 
    <add type="Common.URLRewriter" name="Common" /> 
    最后设置IIS的时候记得要把IIS的表头设置为空。 
    运行下你就能实现了 
    </httpModules>

  • 相关阅读:
    async中series的实现 javascript构件
    6.算法-计数排序
    5.算法-快速排序
    4.堆排序
    3.分治法研究-搜索数组中的最长连续递增子集
    字典树(Trie)学习笔记
    并查集笔记
    求树的遍历
    P1087 FBI树
    P5017 摆渡车
  • 原文地址:https://www.cnblogs.com/liangxiaofeng/p/5620151.html
Copyright © 2011-2022 走看看