URLRewrite伪静态与AspNetPager分页控件的结合

URLRewrite伪静态后AspNetPager分页控件列表输出的静态化方法

首先设置WEB.CONFIG

<RewriterRule>
<LookFor>~/article_list_(\d{1,6})_(\d{1,6})\.htm</LookFor>
<SendTo>~/article_list.aspx?classid=$1&amp;page=$2</SendTo>
</RewriterRule>

注:第一个参数是类别ID,第二个参数是分页数字(第几页)!

再者在 在AspNetPager前台注册的时候一定要写UrlPaging="true"

<%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>

<webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="true"
           FirstPageText="首页" NextPageText="下一页" PrevPageText="前一页" LastPageText="尾页"
           PageSize="20" ShowInputBox="Always" CustomInfoHTML="共%PageCount%页,当前为第%CurrentPageIndex%页,每页%PageSize%条"
           onpagechanged="AspNetPager1_PageChanged" UrlPaging="true">
</webdiyer:AspNetPager>

最后在CS文件中对ASPNETPAGER控件输出URL进行控制

this.AspNetPager1.EnableUrlRewriting = true;
this.AspNetPager1.UrlRewritePattern = "Article_list_" + classid.ToString() + "_{0}.html";

其中classid.ToString()为分类ID 、{0}为页数

只要这三点都做到了!分页应该都是可以实现的! 如果实现不了! 我估计是程序问题! 呵呵!

分页的时候我们也希望url是伪静态的,那么如下操作就ok了

前台显示页面: 其中 EnableUrlRewriting="true" UrlRewritePattern="~/ck_chanpin_{0}.html" 这句非常重要

<webdiyer:AspNetPager ID="myAspNetPager" runat="server" AlwaysShow="false" CustomInfoHTML="共%PageCount%页,当前为第%CurrentPageIndex%页,每页%PageSize%条"
            Font-Size="12px" HorizontalAlign="center" OnPageChanged="myAspNetPager_OnPageChanged" ShowCustomInfoSection="Right" Width="100%" 
            CssClass="neirong-1" FirstPageText="首 页" LastPageText="末 页" NextPageText="下一页" PrevPageText="上一页" 
            PageSize="10"
            EnableUrlRewriting="true"
            UrlRewritePattern="~/ck_chanpin_{0}.html"
            >

Web.config:

   <!-- 开始 -->
  <configSections>
  <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
  </configSections>
  <RewriterConfig>
  <Rules>
    <RewriterRule>
    <LookFor>~/ck_chanpin_(\d+).html</LookFor>
    <SendTo>~/ck_chanpin.aspx?page=$1</SendTo>
    </RewriterRule>
  </Rules>
</RewriterConfig> 
<!-- 结束 -->
<system.web>
    <httpHandlers>
      <add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="True" />
      <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
      <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
    </httpHandlers>
</system.web>

你可能感兴趣的:(urlrewrite)