-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoute.cs
344 lines (270 loc) · 11.6 KB
/
Route.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;
using System.Web.Routing;
using LL.Common;
using LL.Common.EnumClass;
using Project.Common;
/// <summary>
///LLRoute 的摘要说明
/// </summary>
public class Route
{
public Route()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// 转发规则
/// </summary>
///
public static string UrlFormatPrefix_LeiBie = "leibie-";
public static string UrlFormatPrefix_ClassID = "c";
public static string UrlFormatPrefix_BClassID = "b";
public static string UrlFormatPrefix_ZhaoBiaoList = "z-";
public static string UrlFormatPrefix_List = "list-";
private static string RouteSubDomainValueParm_ClassID = UrlFormatPrefix_ClassID + "{" + PubConstant.Key_ClassID + "}.aspx";
private static string RouteSubDomainValueParm_BClassID = UrlFormatPrefix_BClassID + "{" + PubConstant.Key_BClassID + "}.aspx";
private static string RouteSubDomainValueParm_LeiBie = UrlFormatPrefix_LeiBie + "{leibie}.aspx";
private static string RouteSubDomainPageParam_List = UrlFormatPrefix_List + "{" + PubConstant.Key_Route_ListParams + "}.aspx";
private static string RouteValueParm_ClassID = "{page}/" + UrlFormatPrefix_ClassID + "{" + PubConstant.Key_ClassID + "}.aspx";
private static string RouteValueParm_BClassID = "{page}/" + UrlFormatPrefix_BClassID + "{" + PubConstant.Key_BClassID + "}.aspx";
private static string RouteValueParm_LeiBie = "{page}/" + UrlFormatPrefix_LeiBie + "{leibie}.aspx";
private static string RouteValueParm_DetailPage = "{page}/{id}.html";
private static string RouteValueParm_DetailPage2 = "{page}/{id}.aspx";
private static string RoutePageParam_List = "{page}/" + UrlFormatPrefix_List + "{" + PubConstant.Key_Route_ListParams + "}.aspx";
private static string RoutePageParam_List_ZhaoBiao = "{page}/" + UrlFormatPrefix_ZhaoBiaoList + "{" + PubConstant.Key_Route_ListParams + "}.aspx";
private static string RePageSubDomainList = "~/list.aspx";
private static string RePageList = "~/{page}/list.aspx";
private static string RePageDetail = "~/{page}/detail.aspx";
private static string RePageList_ZhaoBiao = "~/{page}/index.aspx";
public static void RouteRule()
{
RouteTable.Routes.MapPageRoute("subdomain-list-classid", RouteSubDomainValueParm_ClassID, RePageSubDomainList);
RouteTable.Routes.MapPageRoute("subdomain-list-bclassid", RouteSubDomainValueParm_BClassID, RePageSubDomainList);
RouteTable.Routes.MapPageRoute("subdomain-list-param", RouteSubDomainPageParam_List, RePageSubDomainList);
RouteTable.Routes.MapPageRoute("subdomain-list-leibie", RouteSubDomainValueParm_LeiBie, RePageSubDomainList);
RouteTable.Routes.MapPageRoute("list-classid", RouteValueParm_ClassID, RePageList);
RouteTable.Routes.MapPageRoute("list-bclassid", RouteValueParm_BClassID, RePageList);
RouteTable.Routes.MapPageRoute("list-leibie", RouteValueParm_LeiBie, RePageList);
RouteTable.Routes.MapPageRoute("list-listparms", RoutePageParam_List, RePageList);
RouteTable.Routes.MapPageRoute("detail", RouteValueParm_DetailPage, RePageDetail, false, new RouteValueDictionary { }, new RouteValueDictionary { { "id", @"\d{1,10}" } });
RouteTable.Routes.MapPageRoute("detail2", RouteValueParm_DetailPage2, RePageDetail, false, new RouteValueDictionary { }, new RouteValueDictionary { { "id", @"\d{1,10}" } });
RouteTable.Routes.MapPageRoute("searchpage", RoutePageParam_List_ZhaoBiao, RePageList_ZhaoBiao);
}
#region 域名地址常量
public static string MainDomain = LL.Common.Cache.ConfigManager.MainDomain;
//根据Dir得到域名
public static string GetSubMainByDir(string dir)
{
dir = dir.Trim().ToLower();
return dir;
}
#endregion
#region routeRewritePath
public static void RouteA(string url)
{
//总规则
string detailPageParmRule = @"^\d{1,10}-\d{1,10}\.html$";
string listPageParmRule = @"^\d{1,10}\.html$";
//转发前缀
string reUrl = url.Substring(0, url.LastIndexOf('/') + 1);
//结页面
string page = url.Substring(reUrl.Length);
string classid = "";
string id = "";
ReListPage(classid, id, reUrl, page, listPageParmRule);
ReDetailPage(classid, id, reUrl, page, detailPageParmRule);
}
/// <summary>
/// 转发详细页
/// </summary>
/// <param name="classid"></param>
/// <param name="id"></param>
/// <param name="reUrl"></param>
/// <param name="page"></param>
/// <param name="detailPageParmRule"></param>
private static void ReDetailPage(string classid, string id, string reUrl, string page, string detailPageParmRule)
{
Regex reg = new Regex(detailPageParmRule);
Match m = reg.Match(page);
if (m.Success)
{
page = m.Groups[0].Value.Replace(@".html", "");
string[] arrV = page.Split(new char[] { '-' });
classid = arrV[0];
id = arrV[1];
reUrl = string.Format("{0}detail.aspx?classid={1}&id={1}", reUrl, classid, id);
HttpContext.Current.RewritePath(reUrl);
}
}
/// <summary>
/// 转发列表页
/// </summary>
/// <param name="classid"></param>
/// <param name="id"></param>
/// <param name="reUrl"></param>
/// <param name="page"></param>
/// <param name="listPageParmRule"></param>
private static void ReListPage(string classid, string id, string reUrl, string page, string listPageParmRule)
{
//列表页转发
Regex reg = new Regex(listPageParmRule);
Match m = reg.Match(listPageParmRule);
if (m.Success)
{
classid = m.Groups[0].Value.Replace(@".html", "");
reUrl = string.Format("{0}list.aspx?classid={1}&id={0}", reUrl, classid);
HttpContext.Current.RewritePath(reUrl);
}
}
#endregion
#region 详细页url格式
public static string UrlInfoDetail(object defaultUrl, object reTitleurl)
{
if (!string.IsNullOrEmpty(reTitleurl.ToString()) && reTitleurl.ToString() != "0")
{
if (reTitleurl.ToString().Contains("http://www.LL.org.cn/e/space/"))
{
reTitleurl = reTitleurl.ToString().Replace("http://www.LL.org.cn/e/space/", "/VipWebSite/index.aspx");
}
return reTitleurl.ToString();
}
else
{
return defaultUrl.ToString();
}
}
//详细页url
public static string UrlDetailPage(PageDirectory dir, object id, object classid, object newstime, object titleUrl)
{
//目前先不用时间
string defaultUrl = string.Format("/{0}/{1}.aspx", dir.ToString(), id);
return UrlInfoDetail(defaultUrl, titleUrl);
}
#region 静态页路径
public static string GetDetailPagePathName(DateTime newstime, object id)
{
return GetDetailPagePathName("",newstime,id);
}
public static string GetDetailPagePathName(string domain,DateTime newstime,object id)
{
string defaultUrl = string.Format("{0}/{1}.html", newstime.ToString("yyyy-MM-dd"), id);
if (!string.IsNullOrEmpty(domain))
{
defaultUrl = string.Format("{0}/{1}", domain, defaultUrl);
}
return defaultUrl;
}
#endregion
/// <summary>
/// 在外围进行datetime转换
/// </summary>
/// <param name="domain">不能为空</param>
/// <param name="dir"></param>
/// <param name="id"></param>
/// <param name="titleUrl"></param>
/// <returns></returns>
public static string UrlDomainDetailPage(string domain, DateTime newsitme, object id, object titleUrl)
{
string defaultUrl=GetDetailPagePathName(domain,newsitme,id);
return UrlInfoDetail(defaultUrl, titleUrl);
}
public static string UrlDetailPage(string domain, PageDirectory dir, object id, object classid, object newstime, object titleUrl)
{
string defaultUrl = string.Format("{0}/{1}/{2}", domain, dir.ToString(), GetDetailPagePathName(Format.DataConvertToDateTime(newstime),id));
return UrlInfoDetail(defaultUrl, titleUrl);
}
/// <summary>
///返回 ID.aspx 不包括 时间路径
/// </summary>
/// <param name="domain"></param>
/// <param name="dri"></param>
/// <param name="id"></param>
/// <param name="titleUrl"></param>
/// <returns></returns>
public static string UrlDetailPage(string domain, PageDirectory dir, object id, object titleUrl)
{
string defaultUrl = string.Format("/{0}/{1}.aspx",dir, id);
if (!string.IsNullOrEmpty(domain))
{
defaultUrl = string.Format("{0}{1}",domain, defaultUrl);
}
return UrlInfoDetail(defaultUrl, titleUrl);
}
public static string UrlDetailPage_ASPX(string domain, PageDirectory dir, object id, object titleUrl)
{
string defaultUrl = string.Format("/{0}/{1}.aspx", dir, id);
if (!string.IsNullOrEmpty(domain))
{
defaultUrl = string.Format("{0}{1}", domain, defaultUrl);
}
return UrlInfoDetail(defaultUrl, titleUrl);
}
public static string UrlDetailPage(object id, object classid, object newstime, object titleUrl)
{
//目前先不用时间
string defaultUrl = GetDetailPagePathName(Format.DataConvertToDateTime(newstime), id);
return UrlInfoDetail(defaultUrl, titleUrl);
}
#endregion
#region 列表页静态化路径
public static string UrlListPageByClassID(PageDirectory dir, object classid)
{
string url = string.Format("/{0}/{1}", dir.ToString(), UrlListPageByClassID(classid));
return url;
}
public static string UrlListPageByClassID(object classid)
{
string url = string.Format("{0}{1}.aspx", UrlFormatPrefix_ClassID, classid);
return url;
}
public static string UrlListPageByBClassID(object classid)
{
string url = string.Format("{0}{1}.aspx", UrlFormatPrefix_BClassID, classid);
return url;
}
#endregion
/// <summary>
/// 按类别查询
/// </summary>
/// <param name="leibieValue"></param>
/// <returns></returns>
public static string UrlListPageByLeiBie(object leibieValue)
{
string url = string.Format("{0}{1}.aspx", UrlFormatPrefix_LeiBie, leibieValue);
return url;
}
public static string ListPageByZhaoBiao(object parm)
{
string url = string.Format("{0}{1}.aspx", UrlFormatPrefix_ZhaoBiaoList, parm);
return url;
}
public static string ListPageByParms(object parm)
{
string url = string.Format("{0}{1}.aspx", UrlFormatPrefix_List, parm);
return url;
}
public static string UrlDomainListPageByBClassID(string subDomain, object classid)
{
return string.Format("{0}/{1}", subDomain, UrlListPageByBClassID(classid));
}
public static string UrlDomainListPageByParms(string SubDoamin, object param)
{
return string.Format("{0}/{1}", SubDoamin, ListPageByParms(param));
}
public static string UrlDomainListPageByClassID(string subDomain, object classid)
{
return string.Format("{0}/{1}", subDomain, UrlListPageByClassID(classid));
}
public static string UrlDomainListPageByLeiBie(string subDomain, string param)
{
return string.Format("{0}/{1}", subDomain, UrlListPageByLeiBie(param));
}
public static string SubDomain_News { get; set; }
public static string SubDomain_Gsk { get; set; }
}