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"/>
  • 相关阅读:
    使用云(BAE)实现android应用数据的远程存取(MySQL)
    VI键盘图
    IOS 6 UIActivityViewController详解 社交分享
    IOS 计算字体控件盖度, 设置粗体+阴影
    myeclipse中tomcat 7.0 关于64位与32位的冲突问题 ( tcnative1.dll )
    九度OJ 1001 A+B for Matrices
    网站10大常见安全漏洞及解决方案
    js网页如何获取手机屏幕宽度
    常用正则说明
    php中的线程、进程和并发区别
  • 原文地址:https://www.cnblogs.com/ajun/p/2239040.html
Copyright © 2011-2022 走看看