100求一个URL重写的实际例子(URLRewriting)

解决方案 »

  1.   

    http://www.kfnet.cn/Artical.kf?ArticalID=1739&Belong=0&Type=1  (有例子)http://www.cnblogs.com/coollzh/archive/2004/12/11/75471.htmlhttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/urlrewriting.asphttp://dottextwiki.scottwater.com/default.aspx/Dottext.UrlRewriting
      

  2.   

    http://www.microsoft.com/china/msdn/library/webservices/asp.net/URLRewriting.mspx
      

  3.   

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <configSections>
    <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
    </configSections>
    <RewriterConfig>
    <Rules>
    <RewriterRule>
    <LookFor>~/News/c(\d{1,5})\.aspx</LookFor>
    <SendTo>~/News/NewsList.aspx?Cat_ID=$1</SendTo>
    </RewriterRule>
    <RewriterRule>
    <LookFor>~/News/d(\d+)\.aspx</LookFor>
    <SendTo>~/News/NewsDetails.aspx?News_ID=$1</SendTo>
    </RewriterRule>
    </Rules>
    </RewriterConfig>
    <system.web>
    <httpModules>
    <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
    </httpModules>
    <compilation defaultLanguage="c#" debug="true" />
    <customErrors mode="RemoteOnly" />
    <authentication mode="Windows" />
    <authorization>
    <allow users="*" />
    </authorization>
    <trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
    <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
    cookieless="false" timeout="20" />
    <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
    </system.web>
    </configuration>
    分析器错误信息: 找不到文件或程序集名称“URLRewriter”,或找不到它的一个依赖项。源错误: 
    行 18:  <system.web>
    行 19:  <httpModules>
    行 20:  <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
    行 21:  </httpModules>
    行 22:  <compilation defaultLanguage="c#" debug="true" />
     
      

  4.   

    先取得地址在修改後重定向!
    string url = this.Request.Url.ToString();     //取得
    url = url.Replace("index1.aspx","index.aspx");//修改
    Page.Response.Redirect(url);                  //蟲定向
    這是我用到的一個方法!
      

  5.   

    我不太明白<RewriterConfig>
    我的应用有是例如十位的编码例如:0000000001.请问<RewriterRule>
    怎么写.
      

  6.   

    配置:
    <RewriterConfig>
       <Rules>
    <RewriterRule>
        <LookFor>~/(\d{10})\.aspx</LookFor>
         <SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo>
              </RewriterRule>
       </Rules>
    </RewriterConfig>
    完成:
    http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133
    http://localhost/Test4RewriteUrl/0000000133.aspx
    之间的转换我想完成
    http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133
    http://localhost/Test4RewriteUrl/0000000133.html
    之间的转换
    修改:
    <RewriterConfig>
       <Rules>
    <RewriterRule>
        <LookFor>~/(\d{10})\.html</LookFor>
         <SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo>
              </RewriterRule>
       </Rules>
    </RewriterConfig>为什么无效呢?
    我的机器是Server2003的.
    请问是不是要配置什么????
      

  7.   

    配置:
    <RewriterConfig>
       <Rules>
    <RewriterRule>
        <LookFor>~/(\d{10})\.aspx</LookFor>
         <SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo>
              </RewriterRule>
       </Rules>
    </RewriterConfig>
    完成:
    http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133
    http://localhost/Test4RewriteUrl/0000000133.aspx
    之间的转换我想完成
    http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133
    http://localhost/Test4RewriteUrl/0000000133.html
    之间的转换
    修改:
    <RewriterConfig>
       <Rules>
    <RewriterRule>
        <LookFor>~/(\d{10})\.html</LookFor>
         <SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo>
              </RewriterRule>
       </Rules>
    </RewriterConfig>为什么无效呢?
    我的机器是Server2003的.
    请问是不是要配置什么????
    最后的一个小问题了.
    ◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆
      

  8.   

    配置:
    <RewriterConfig>
       <Rules>
    <RewriterRule>
        <LookFor>~/(\d{10})\.aspx</LookFor>
         <SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo>
              </RewriterRule>
       </Rules>
    </RewriterConfig>
    完成:
    http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133
    http://localhost/Test4RewriteUrl/0000000133.aspx
    之间的转换我想完成
    http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133
    http://localhost/Test4RewriteUrl/0000000133.html
    之间的转换
    修改:
    <RewriterConfig>
       <Rules>
    <RewriterRule>
        <LookFor>~/(\d{10})\.html</LookFor>
         <SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo>
              </RewriterRule>
       </Rules>
    </RewriterConfig>为什么无效呢?
    我的机器是Server2003的.
    请问是不是要配置什么????
    最后的一个小问题了.
    ◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆
      

  9.   

    如果重写为其他的类型,IIS中需要添加请求的驱动为aspnetapi.
      

  10.   

    打开 Global.asax.cs 在最上面添加一行 using System.Text.RegularExpressions;然后在 Application_BeginRequest 事件中写入 string strRawUrl = HttpContext.Current.Request.RawUrl;
    string strNewUrl; if (Regex.IsMatch(strRawUrl, @"default.aspx", RegexOptions.IgnoreCase))
    {
    strNewUrl = Regex.Replace(strRawUrl, @"default.aspx", @"showforum.aspx\?fld=1"); HttpContext.Current.RewritePath( strNewUrl );
    }
    else if (Regex.IsMatch(strRawUrl, @"(\d+)0(\d+)0(\d+)0(\d+).html", RegexOptions.IgnoreCase))
    {
    strNewUrl = Regex.Replace(strRawUrl, @"(\d+)0(\d+)0(\d+)0(\d+).html", @"showtopic.aspx\?tid=$1&tpg=$2&bpg=$3&fld=$4"); HttpContext.Current.RewritePath( strNewUrl );
    }
    else if (Regex.IsMatch(strRawUrl, @"showtopic.aspx\?tid=(\d+)&tpg=(\d+)&bpg=(\d+)&fld=(\d+)", RegexOptions.IgnoreCase))
    {
    strNewUrl = Regex.Replace(strRawUrl, @"showtopic.aspx\?tid=(\d+)&tpg=(\d+)&bpg=(\d+)&fld=(\d+)", @"$10$20$30$4.html"); HttpContext.Current.Response.Redirect( strNewUrl );
    }第一个IF是最最简单的第二个IF是当IIS把HTML交给ASP.NET时使用的,嘿嘿第三个IF是为了解决表单提交时IE的地址栏出现真实的URL地址,是第二个IF的逆操作其中正则表达式里的0是分隔符,因为页数、ID的最小址都不可能是0
    用户IE的地址栏中显示的是http://localhost/AdNT/4561230100101.html
    但实际上是http://localhost/AdNT/showtopic.aspx?tid=456123&tpg=10&bpg=1&fld=1楼主,我说的清楚么?^^
      

  11.   

    如果是把重写规则保存XML文件里,可以直接用DataSet读取出来,然后用for循环,找到了匹配的就跳出来
      

  12.   

    忘记说,楼主记得要把DataSet缓存,不然每次都要读取XML倒,三连了……