zoukankan      html  css  js  c++  java
  • URLWrite

    添加一个global.asax文件新增如下代码

      protected void Application_BeginRequest(object sender, EventArgs e)
        {
            string oldUrl = HttpContext.Current.Request.RawUrl;
            UrlRewrite(oldUrl, @"^(.*)/Index\.htm", @"Default1.aspx");
            UrlRewrite(oldUrl, @"^(.+)/view-(\d+)-(.+)\.htm(\?.*)*$", "$1/Default2.aspx?id=$2&type=$3");
            UrlRewrite(oldUrl, @"^(.+)/toptic-(.+)\.htm(\?.*)*$", "$1/view/viewDetail.aspx?ID=$2");

            //(@"^(.+)/(\d+)\.htm(\?.*)*$", "$1/Flue/ListView.aspx?id=$2")  任意字符/数字.htm 对应 flue/listview.aspx?id=数字
        }
        private void UrlRewrite(string oldUrl, string pattern, string replace)
        {
            if (Regex.IsMatch(oldUrl, pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled))
            {
                string newUrl = Regex.Replace(oldUrl, pattern, replace, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                this.Context.RewritePath(newUrl);
            }
        }

    、、、、、、、、、、、、、、、、、、、、、、、

    另外,微软还提供了一个dll文件,URLWriter.dll ,

    我们也可以使用它来直接进行URL重写。

    ①添加引用URLwriter.dll文件

    ②在web.config文件中,找到<configSections>节点,在结束标志</configSections>前添加代码

    第一步
    <configSections>
    <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandlers, URLRewriter">

    </configSections>

    ③在web.config文件中,还是找到<configSections>节点,在结束标志</configSections>后,添加代码

    第二步
    <RewriterConfig>
    <Rules>
    <RewriterRule>
    <LookFor>~/user/blogs.aspx</LookFor>
    <SendTo>~/user/blogs.aspx?id=$1</SendTo>
    </RewriterRule>
    </Rules>
    </RewriterConfig>

    ④找到节点<httpHandlers>,在<httpHandlers>中添加

    <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler,URLRewriter"/>
  • 相关阅读:
    JVM调优--常用JVM监控工具使用
    jvm启动常用参数配置
    公钥和私钥原理
    tcp三次握手四次挥手
    内存泄漏和内存溢出
    hashmap解析
    Visual C++ 6.0 断点调试记录
    C++中输入一组不确定长度的数
    异或
    NULL与nullptr
  • 原文地址:https://www.cnblogs.com/ajun/p/2239040.html
Copyright © 2011-2022 走看看