今天在使用BlogEngine最新版(1.4.5)的过程中,突然发现一个日志分类的重要Bug,严重影响使用。
具体表现:从首页打开子分类(所有非根级分类)的页面通通报404错误。
简单检查,发现BlogEngine在UrlRewrite及通用函数类(Utils)中存在由于字符过滤不严格造成的URL问题。一个简单的修复方法如下:
1、打开BlogEngine.Core工程下的Utils.cs文件,找到两个静态函数【34行】RemoveIllegalCharacters()和【58行】RemoveExtraHyphen(),如下:
- public static string RemoveIllegalCharacters(string text)
- {
- if (string.IsNullOrEmpty(text))
- return text;
-
- text = text.Replace(":", string.Empty);
- text = text.Replace("/", string.Empty);
- text = text.Replace("?", string.Empty);
- text = text.Replace("#", string.Empty);
- text = text.Replace("[", string.Empty);
- text = text.Replace("]", string.Empty);
- text = text.Replace("@", string.Empty);
- text = text.Replace(".", string.Empty);
- text = text.Replace(",", string.Empty);
- text = text.Replace("\"", string.Empty);
- text = text.Replace("&", string.Empty);
- text = text.Replace("'", string.Empty);
- text = text.Replace(" ", "-");
- text = RemoveDiacritics(text);
- text = RemoveExtraHyphen(text);
-
- return HttpUtility.UrlEncode(text).Replace("%", string.Empty);
- }
-
- private static string RemoveExtraHyphen(string text)
- {
- if (text.Contains("--"))
- {
- text = text.Replace("--", "-");
- return RemoveExtraHyphen(text);
- }
-
- return text;
- }
2、修改如下:
- public static string RemoveIllegalCharacters(string text)
- {
- if (string.IsNullOrEmpty(text))
- return text;
-
- text = text.Replace(":", string.Empty);
- text = text.Replace("/", string.Empty);
- text = text.Replace("?", string.Empty);
- text = text.Replace("#", string.Empty);
- text = text.Replace("[", string.Empty);
- text = text.Replace("]", string.Empty);
- text = text.Replace("@", string.Empty);
- text = text.Replace(".", string.Empty);
- text = text.Replace(",", string.Empty);
- text = text.Replace("\"", string.Empty);
- text = text.Replace("&", string.Empty);
- text = text.Replace("'", string.Empty);
- text = text.Replace(" ", "-");
- text = RemoveDiacritics(text);
- text = RemoveExtraHyphen(text);
-
- return HttpUtility.UrlEncode(text).Replace("%7c", "/").Replace("%", string.Empty);
- }
-
- private static string RemoveExtraHyphen(string text)
- {
- if (text.Contains("---"))
- {
- text = text.Replace("---", "|");
- return RemoveExtraHyphen(text);
- }
- else if (text.Contains("--"))
- {
- text = text.Replace("--", "-");
- return RemoveExtraHyphen(text);
- }
-
- return text;
- }
3、修改好后,重新编译BlogEngine.Core后,把所得BlogEngine.Core.dll替换一下原来的即可,呵呵。
Currently rated 3.2 by 11 people
- Currently 3.181818/5 Stars.
- 1
- 2
- 3
- 4
- 5