利用Redis解决Url过长的问题

时间:2023-03-08 19:56:06

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

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

存Redis:

 /// <summary>
/// when tagids length > 50 then shortening the ids
/// </summary>
/// <param name="tagIDs"></param>
/// <returns>tags or guid</returns>
protected static string RedirectTags(string tagIDs)
{
string s = string.Empty;
if (tagIDs.Length > )
{
s = "__" + GetUid();
UserSession.SetRedisString(s, tagIDs);
}
else
s = tagIDs;
return s;
} /// <summary>
/// get guid
/// </summary>
/// <returns>new guid</returns>
public static string GetUid()
{
var Uid = Guid.NewGuid().ToString(); return Uid;
}

读Redis:

 if (TagIDs.Length >  && TagIDs.Substring(, ) == "__")
TagIDs = UserSession.GetRedisString(TagIDs);

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