zoukankan      html  css  js  c++  java
  • URL重写

    http://localhost:37977/UrlWrite.ashx?id=9
    URL重写成下面的访问方式,有利于SEO搜索引擎
    http://localhost:37977/UrlWrite-8.ashx

    实现方法(用正则表达式匹配获取当前请求的虚拟路径):

    /// <summary>
    /// 当一个请求过来的时候会被调用,html静态文件是iis直接把文件给到浏览器,不经过asp.net引擎处理
    /// 所以不会调用Application_BeginRequest方法
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        File.AppendAllText(@"c:1.txt", DateTime.Now + "Application_BeginRequest" 
            + Context.Request.RawUrl + "
    ");
        //Context.RewritePath("HtmlPage1.html");
        //url重写
        Match match = Regex.Match(Context.Request.Path, @"^/UrlWrite-(d+).ashx$");
        if (match.Success)
        {
            string id = match.Groups[1].Value;
            Context.RewritePath("/UrlWrite.ashx?id=" + id);
        }
    }
  • 相关阅读:
    写优先
    生产者消费者信号量的个人理解
    向上过滤
    操作系统之进程调度算法笔记
    idea学习
    计算机网络之网络层
    rest-framework routers
    rest framework ViewSet
    rest framework Genericview
    rest framework Views
  • 原文地址:https://www.cnblogs.com/genesis/p/5061123.html
Copyright © 2011-2022 走看看