文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>利用 HttpModule 重写 URL

利用 HttpModule 重写 URL

时间:2011-04-19  来源:solomon_Blog

    void context_BeginRequest(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;

        HttpContext context = application.Context;
        HttpResponse response = application.Response;

        string path = context.Request.Path;

        string file = System.IO.Path.GetFileName(path);

        Regex regex = new Regex(@"(\w+)_(\w+)(\d).html", RegexOptions.Compiled);
        Regex regex2 = new Regex(@"(\w+).html", RegexOptions.Compiled);

        Match match = regex.Match(file);
        Match match2 = regex2.Match(file);


        if (match2.Success)
        {
            string url = match2.Groups[1].Value;
            context.RewritePath(url + ".aspx");
        }
        if (match.Success)
        {
            string url = match.Groups[1].Value;
            string parm = match.Groups[2].Value;
            string parmValue=match.Groups[3].Value;

            string reWritePath = url + ".aspx?" + parm + "=" + parmValue;

            context.RewritePath(reWritePath);
        }

    }

    #region IHttpModule 成员

    public void Dispose()
    {
        throw new NotImplementedException();
    }

    public void Init(HttpApplication context)
    {
        context.BeginRequest += new EventHandler(context_BeginRequest);
    }

    #endregion
  1. <httpModules>  
  2.  <add name="UrlReWriter" type="UrlReWriter"/>  
  3.  </httpModules>  

如果要实现全站伪静态需要在IIS配置中添加.html映射

源:http://blog.csdn.net/zhoufoxcn/archive/2009/07/14/4346356.aspx

相关阅读 更多 +
排行榜 更多 +
下载oe

下载oe

金融理财 下载
易欧app官方下载安装

易欧app官方下载安装

金融理财 下载
易欧app官方免费下载

易欧app官方免费下载

金融理财 下载