模仿百度搜索的分页 超链接

本文介绍了一种在ASP.NET中实现SEO友好的分页技术。通过使用自定义分页逻辑替代第三方控件,该方案能够更好地支持搜索引擎爬虫抓取页面内容,同时提供了清晰的URL结构和良好的用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原先是用的第三方控件AspNetPager.dll来实现的分页,感觉吧还行...后来弄SEO的时候,老大跑来找我了,蜘蛛采集不到?我晕意思就是说我的改了吧

没办法只能从新弄了,因此就网上找找了,感觉这个还是可以的...

源码:用的三层,换成你自己的

.cs代码

  int ToatalCountRecord;//总记录数  
    int PageItem = 8;//每页显示的条数  
    int CurrentPage = 1;//当前页数  
    protected void Page_Load(object sender, EventArgs e)
    {

      if (!IsPostBack)
        {
         

          if (Request.QueryString["page"] != null)
            {
                string a = Request.QueryString["page"];
                CurrentPage = Convert.ToInt32(a);
            }


GetVproduct(43);

        }

    }

public void GetVproduct(int brandid)
    {
        DataTable dt = vPrdouctRules.GetProBybrandid(brandid);
        if (dt.Rows.Count > 0)
        {
            string where = " brandid =" + brandid + " and DeleteFlag=0 and Gbisweb='Y' and IsSpecial=0";
            rpVproduct.DataSource = vPrdouctRules.Select(PageItem, CurrentPage, where, "autoid", true, false);
            rpVproduct.DataBind();
        }
        else
        {
            product1.Visible = false;
        }
        ToatalCountRecord = dt.Rows.Count;
        BuildPages();

    }


 private void BuildPages()
    {
        int Step = 5;//偏移量  
        int LeftNum = 0;//左界限  
        int RightNum = 0;//右界限  
        string seoName = BrandVsSeoRule.GetModelByBid(Convert.ToInt32(brandid)).SeoName;
        string PageUrl = brandDetail;
        int PageCount = (int)Math.Ceiling((double)(ToatalCountRecord) / PageItem);
        if (CurrentPage - Step < 1)
        {
            LeftNum = 1;
        }
        else
        {
            LeftNum = CurrentPage - Step;
        }
        if (CurrentPage + Step > PageCount)
        {
            RightNum = PageCount;
        }
        else
        {
            RightNum = CurrentPage + Step;
        }
        StringBuilder OutPut = new StringBuilder();
        OutPut.Append("<ul>");
        if (CurrentPage != 1)
        {
            OutPut.Append(" <li><span> <a href='" + PageUrl + "/" + seoName + "/" + brandid + "_" + (CurrentPage - 1) + ".html" + "'>" + "<" + "  </a></span></li>");
        }
        else
        {
            OutPut.Append("<li class='pageno'><span><a href='#'><</a></span></li>");
        }

        for (int i = LeftNum; i <= RightNum; i++)
        {
            if (i == CurrentPage)
            {
                OutPut.Append("<li class='on'><a href='" + PageUrl + "/" + seoName + "/" + brandid + "_" + i.ToString() + ".html" + "'> " + " " + i.ToString() + "" + "</a></li>");//自己拼写自己的样式,我们美工做好的UL里面LI
            }
            else
            {
                OutPut.Append("<li>  <a href='" + PageUrl + "/" + seoName + "/" + brandid + "_" + i.ToString() + ".html" + "'>" + " " + i.ToString() + " " + "  </a></li>");
            }
        }
        if (CurrentPage < PageCount)
        {
            OutPut.Append("<li> <span> <a href='" + PageUrl + "/" + seoName + "/" + brandid + "_" + (CurrentPage + 1) + ".html" + "'>" + ">" + "  </a></span></li>");
        }
        else
        {
            OutPut.Append("<li class='pageno'><span><a href='#'>></a></span></li>");
        }
        OutPut.Append("</ul>");
        this.product1.InnerHtml = OutPut.ToString();
    }

.aspx代码

 <asp:Repeater ID="rpVproduct" runat="server" >
                    <ItemTemplate>
                   <%#Eval("PrcName")%>
                    </ItemTemplate>
 </asp:Repeater>

 <div class="page" id="product1" runat="server">

</div>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值