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"/>
  • 相关阅读:
    验证授权【msdn】
    实战 Comet 应用程序开发
    ASP.NET Forms验证 实现子域名(SubDomain)共享登陆下的缺陷 [转]
    分享WordPress博客搜索引擎优化的六点经验 博客园 cnbogs
    支持支付宝(Alipay)付款的三个美国主机商
    认证,授权2
    登录代码,程序不是作文
    Google 的PageRank值对网站成功有多重要
    SQL Server 2005 Service Broker 初探 [摘抄]
    jQuerySelectors(选择器)的使用(四五、内容篇&可见性篇) cnblogs zhuan
  • 原文地址:https://www.cnblogs.com/ajun/p/2239040.html
Copyright © 2011-2022 走看看