ASP.NET伪静态的方法及相关资料

1. 添加URLRewriter.dll引用

2. 配置web.config的基本信息

 <configSections>
    <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
  </configSections>
<system.web>
  <httpHandlers>
    <!--使用URLRewriter.dll    -->
  <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
  <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />

</httpHandlers>
    <compilation debug="true" targetFramework="4.0"/>
  </system.web>
<!--重写规则-->
  <RewriterConfig>
    <Rules>
      <RewriterRule>
        <LookFor>~/index.html</LookFor>
        <SendTo>~/Index.aspx</SendTo>
      </RewriterRule>
      <RewriterRule>
        <LookFor>~/Product/detail/item/([0-9]*).html</LookFor>
        <SendTo>~/Product_Detail.aspx?ID=$1</SendTo>
      </RewriterRule>

      <!--分页规则开始-->
      <RewriterRule>
        <LookFor>~/Product/list/item/(.*)_(.*)\.html</LookFor>
        <SendTo>~/Product_List.aspx?ID=$1&amp;page=$2</SendTo>
      </RewriterRule>
      <RewriterRule>
        <LookFor>~/Product/list/item/(.*)\.html</LookFor>
        <SendTo>~/Product_List.aspx?ID=$1</SendTo>
      </RewriterRule>
      <!--分页规则结束-->

      <!--分页规则开始-->
      <RewriterRule>
        <LookFor>~/Product/list/(.*)_(.*)_(.*)\.html</LookFor>
        <SendTo>~/Product_List.aspx?type=$1&amp;ID=$2&amp;page=$3</SendTo>
      </RewriterRule>

      <RewriterRule>
        <LookFor>~/Product/list/(.*)_(.*)\.html</LookFor>
        <SendTo>~/Product_List.aspx?type=$1&amp;ID=$2</SendTo>
      </RewriterRule>
      <RewriterRule>
        <LookFor>~/Product/BuyNow.html</LookFor>
        <SendTo>~/Buy_now.aspx</SendTo>
      </RewriterRule>
      <RewriterRule>
        <LookFor>~/AlipayInfo.html</LookFor>
        <SendTo>~/Skin/js/AlipayInfo.aspx</SendTo>
      </RewriterRule>

      <RewriterRule>
        <LookFor>~/PayToAlipay.html</LookFor>
        <SendTo>~/Skin/js/PayToAlipay.aspx</SendTo>
      </RewriterRule>
      <RewriterRule>
        <LookFor>~/PayDetail.html</LookFor>
        <SendTo>~/skin/js/Paydetail.aspx</SendTo>
      </RewriterRule>
      <RewriterRule>
        <LookFor>~/404error.html</LookFor>
        <SendTo>~/404.aspx</SendTo>
      </RewriterRule>
      <RewriterRule>
        <LookFor>~/ShoppingCart.html</LookFor>
        <SendTo>~/ShoppingCart.aspx</SendTo>
      </RewriterRule>
      <RewriterRule>
        <LookFor>~/CartList.html</LookFor>
        <SendTo>~/CartListBuyNow.aspx</SendTo>
      </RewriterRule>
      <RewriterRule>
        <LookFor>~/CartAlipay.html</LookFor>
        <SendTo>~/CartListCookie/CartListToAlipay.aspx</SendTo>
      </RewriterRule>
      <RewriterRule>
        <LookFor>~/CartWxpay.html</LookFor>
        <SendTo>~/CartListCookie/CarListWxPayApi.aspx</SendTo>
      </RewriterRule>
      <RewriterRule>
        <LookFor>~/Agreement/index.html</LookFor>
        <SendTo>~/Agreement.aspx</SendTo>
      </RewriterRule>
    </Rules>
  </RewriterConfig>

 到这里伪静态就可以使用了

3.伪静态分页

  ⑴ 分页控件代码

 <webdiyer:AspNetPager ID="AspNetPager1" runat="server" FirstPageText="首页" LastPageText="尾页"
     NextPageText="下一页" PageIndexBoxType="DropDownList" PrevPageText="上一页" ShowCustomInfoSection="Left"
     ShowPageIndexBox="Always" SubmitButtonText="Go" ShowPageIndex="False" TextAfterPageIndexBox=""
     TextBeforePageIndexBox="转到" AlwaysShow="True" LayoutType="Table" CssClass="paginator"
     CustomInfoClass="paginator" CustomInfoSectionWidth="" Wrap="False" PageSize="10"
     OnPageChanging="AspNetPager1_PageChanging" UrlPaging="True">
</webdiyer:AspNetPager>

 

⑵ .cs代码

 DataDictRef ddr = new DataDictRefBLL().GetDetail(type);
    if (ddr != null)
    {
      typename = "<span>" + ddr.DataDictRefName + "<span/>";
      replist.DataSource = new T_T_BusinessProductBLL().GetListByTypeID(type, this.AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, ref recordCount);
      AspNetPager1.UrlRewritePattern = "/Product/list/" + type + "_" + ID + "_{0}.html";
   }else
    {
       Response.Redirect("/404error.html");
    }

 

 

4. 相关参考质料

(1)在ASP.NET中执行URL重写

(2)ASP.NET 实现伪静态网页方法

(3)IIS7 伪静态 web.config 配置方法

(4)ASP.NET伪静态页面的实现和伪静态在IIS7.0中的配置

(5)ASP.NET伪静态实现

 

你可能感兴趣的:(ASP.NET伪静态的方法及相关资料)