利用Redis解决Url过长的问题

做网站,接手别人的代码,发现url有时候会过长导致页面直接翻掉。

后来想了一下可以利用redis将太长的地方暂存,加载页面时获取即可。

存Redis:

 1 /// <summary>
 2         /// when tagids length > 50 then shortening the ids
 3         /// </summary>
 4         /// <param name="tagIDs"></param>
 5         /// <returns>tags or guid</returns>
 6         protected static string RedirectTags(string tagIDs)
 7         {
 8             string s = string.Empty;
 9             if (tagIDs.Length > 50)
10             {
11                 s = "__" + GetUid();
12                 UserSession.SetRedisString(s, tagIDs);
13             }
14             else
15                 s = tagIDs;
16             return s;
17         }
18 
19         /// <summary>
20         /// get guid
21         /// </summary>
22         /// <returns>new guid</returns>
23         public static string GetUid()
24         {
25             var Uid = Guid.NewGuid().ToString();
26 
27             return Uid;
28         }
View Code

读Redis:

1 if (TagIDs.Length > 2 && TagIDs.Substring(0, 2) == "__")
2                 TagIDs = UserSession.GetRedisString(TagIDs);
View Code

遇到前台url拼装,利用callback填充。

原文地址:https://www.cnblogs.com/riusmary/p/6123019.html