1.isapi_rewrite可自行百度,用的是最新版
//配置好isapi后,需要注意的是32位有完全破解版的,64位的暂时没找到,具体可搜索百度,把页面放在iis上,并写页面的规则,以下是部分规则
RewriteRule ^[/zhuanti/]+SubJectIndex.html /zhuanti/SubJectIndex.aspx RewriteRule ^[/zhuanti/]+SubJectBrand_([0-9]*)_([0-9]*).html /zhuanti/SubJectBrand.aspx\?Type=$1\&Page=$2 RewriteRule ^[/zhuanti/]+BrandStore_(\d+)_(\d+).html /zhuanti/BrandStore.aspx\?Are=$1\&Page=$2
2.页面上调用分页方法
#region 分页参数 protected int Page;//当前页 protected int Pagesize = 4; //每页 protected int Totalcount; //OUT数据总数 protected string Pagelist = string.Empty; #endregion
Pagelist = Utils.get_page_link2(Pagesize, Page, Totalcount, "SubJectBrand.html/*后面用方法把前缀和后缀分离了出来*/",Type/*参数,可写多个*/, "__id__"/*分页参数占位符*/);
3.分页的类里,有2个分页,可根据需要重写分页html代码
/// <summary> /// 分页符 /// </summary> public class Utils { #region 返回分页字符串 /// <summary> /// 返回分页字符串 /// </summary> /// <param name="pagesize">页面大小</param> /// <param name="pageindex">当前页</param> /// <param name="totalcount">记录总数</param> /// <param name="url">URL名称</param> /// <param name="_params">传输参数</param> public static string get_page_link(int pagesize, int pageindex, int totalcount, string url, params object[] _params) { return Utils.OutPageList(pagesize, pageindex, totalcount, Linkurl(url, _params), 4); } /// <summary> /// 返回分页字符串2 /// </summary> /// <param name="pagesize">页面大小</param> /// <param name="pageindex">当前页</param> /// <param name="totalcount">记录总数</param> /// <param name="url">URL名称</param> /// <param name="_params">传输参数</param> public static string get_page_link2(int pagesize, int pageindex, int totalcount, string url, params object[] _params) { return Utils.OutPageList2(pagesize, pageindex, totalcount, Linkurl(url, _params), 4); } /// <summary> /// 返回分页字符串 /// </summary> /// <param name="pagesize">页面大小</param> /// <param name="pageindex">当前页</param> /// <param name="totalcount">记录总数</param> /// <param name="linkurl">链接地址</param> public static string get_page_link(int pagesize, int pageindex, int totalcount, string linkurl) { return Utils.OutPageList(pagesize, pageindex, totalcount, linkurl, 4); } #endregion #region 显示分页 /// <summary> /// 返回分页页码 /// </summary> /// <param name="pageSize">页面大小</param> /// <param name="pageIndex">当前页</param> /// <param name="totalCount">总记录数</param> /// <param name="linkUrl">链接地址,__id__代表页码</param> /// <param name="centSize">中间页码数量</param> /// <returns></returns> public static string OutPageList(int pageSize, int pageIndex, int totalCount, string linkUrl, int centSize) { //计算页数 if (totalCount < 1 || pageSize < 1) { return ""; } int pageCount = totalCount / pageSize; if (pageCount < 1) { return ""; } if (totalCount % pageSize > 0) { pageCount += 1; } if (pageCount <= 1) { return ""; } StringBuilder pageStr = new StringBuilder(); string pageId = "__id__"; string firstBtn = "<a href=\"" + ReplaceStr(linkUrl, pageId, (pageIndex - 1).ToString()) + "\">«上一页</a>"; string lastBtn = "<a href=\"" + ReplaceStr(linkUrl, pageId, (pageIndex + 1).ToString()) + "\">下一页»</a>"; string firstStr = "<a href=\"" + ReplaceStr(linkUrl, pageId, "1") + "\">1</a>"; string lastStr = "<a href=\"" + ReplaceStr(linkUrl, pageId, pageCount.ToString()) + "\">" + pageCount.ToString() + "</a>"; if (pageIndex <= 1) { firstBtn = "<span class=\"disabled\">«上一页</span>"; } if (pageIndex >= pageCount) { lastBtn = "<span class=\"disabled\">下一页»</span>"; } if (pageIndex == 1) { firstStr = "<span class=\"current\">1</span>"; } if (pageIndex == pageCount) { lastStr = "<span class=\"current\">" + pageCount.ToString() + "</span>"; } int firstNum = pageIndex - (centSize / 2); //中间开始的页码 if (pageIndex < centSize) firstNum = 2; int lastNum = pageIndex + centSize - ((centSize / 2) + 1); //中间结束的页码 if (lastNum >= pageCount) lastNum = pageCount - 1; pageStr.Append("<span>共" + totalCount + "记录</span>"); pageStr.Append(firstBtn + firstStr); if (pageIndex >= centSize) { pageStr.Append("<span>...</span>\n"); } for (int i = firstNum; i <= lastNum; i++) { if (i == pageIndex) { pageStr.Append("<span class=\"current\">" + i + "</span>"); } else { pageStr.Append("<a href=\"" + ReplaceStr(linkUrl, pageId, i.ToString()) + "\">" + i + "</a>"); } } if (pageCount - pageIndex > centSize - ((centSize / 2))) { pageStr.Append("<span>...</span>"); } pageStr.Append(lastStr + lastBtn); return pageStr.ToString(); } #endregion #region 显示分页2 /// <summary> /// 返回分页页码 /// </summary> /// <param name="pageSize">页面大小</param> /// <param name="pageIndex">当前页</param> /// <param name="totalCount">总记录数</param> /// <param name="linkUrl">链接地址,__id__代表页码</param> /// <param name="centSize">中间页码数量</param> /// <returns></returns> public static string OutPageList2(int pageSize, int pageIndex, int totalCount, string linkUrl, int centSize) { //计算页数 if (totalCount < 1 || pageSize < 1) { return ""; } int pageCount = totalCount / pageSize; if (pageCount < 1) { return ""; } if (totalCount % pageSize > 0) { pageCount += 1; } if (pageCount <= 1) { return ""; } StringBuilder pageStr = new StringBuilder(); string pageId = "__id__"; string firstBtn = "<a href=\"" + ReplaceStr(linkUrl, pageId, (pageIndex - 1).ToString()) + "\"><</a>"; string lastBtn = "<a href=\"" + ReplaceStr(linkUrl, pageId, (pageIndex + 1).ToString()) + "\">></a>"; string firstStr = "<a href=\"" + ReplaceStr(linkUrl, pageId, "1") + "\">1</a>"; string lastStr = "<a href=\"" + ReplaceStr(linkUrl, pageId, pageCount.ToString()) + "\">" + pageCount.ToString() + "</a>"; if (pageIndex <= 1) { firstBtn = "<a class=\"disabled\"><</a>"; } if (pageIndex >= pageCount) { lastBtn = "<a class=\"disabled\">></a>"; } if (pageIndex == 1) { firstStr = "<a class=\"current\">1</a>"; } if (pageIndex == pageCount) { lastStr = "<a class=\"current\">" + pageCount.ToString() + "</a>"; } int firstNum = pageIndex - (centSize / 2); //中间开始的页码 if (pageIndex < centSize) firstNum = 2; int lastNum = pageIndex + centSize - ((centSize / 2) + 1); //中间结束的页码 if (lastNum >= pageCount) lastNum = pageCount - 1; //pageStr.Append("<span>共" + totalCount + "记录</span>"); pageStr.Append(firstBtn + firstStr); //if (pageIndex >= centSize) //{ // pageStr.Append("<span>...</span>\n"); //} for (int i = firstNum; i <= lastNum; i++) { if (i == pageIndex) { pageStr.Append("<a class=\"current\">" + i + "</a>"); } else { pageStr.Append("<a href=\"" + ReplaceStr(linkUrl, pageId, i.ToString()) + "\">" + i + "</a>"); } } if (pageCount - pageIndex > centSize - ((centSize / 2))) { pageStr.Append("<a>...</a>"); } pageStr.Append(lastStr + lastBtn); return pageStr.ToString(); } #endregion #region 替换指定的字符串 /// <summary> /// 替换指定的字符串 /// </summary> /// <param name="originalStr">原字符串</param> /// <param name="oldStr">旧字符串</param> /// <param name="newStr">新字符串</param> /// <returns></returns> public static string ReplaceStr(string originalStr, string oldStr, string newStr) { if (string.IsNullOrEmpty(oldStr)) { return ""; } return originalStr.Replace(oldStr, newStr); } #endregion #region 返回URL重写参数和地址 /// <summary> /// 返回URL重写参数和地址 /// </summary> public static string Linkurl(string url, params object[] _params) { if (string.IsNullOrEmpty(url)) { throw new Exception("无url地址错误"); } else if (url.LastIndexOf(".", System.StringComparison.Ordinal) > 0) { var txt = url.Split('.'); if (_params.Length > 0) { StringBuilder str = new StringBuilder(); for (int i = 0; i < _params.Length; i++) {
//可根据isapi规则不同,把_换成/什么都行 str.AppendFormat("_{0}", _params[i]); } return txt[0] + str.ToString() + url.Substring(url.LastIndexOf(".", System.StringComparison.Ordinal)); } else { return txt[0] + url.Substring(url.LastIndexOf(".", System.StringComparison.Ordinal)); } } else { throw new Exception("url地址无后缀名"); } } #endregion }
你将独自前行,你会遇到友好,也会遇到恶意,不管你多么善良,因为世间就是这样,不好,不坏.