[英]Japanese Characters with IIS7 URL Rewrite asp.net
请帮助我使用重写模块构建了我的网站[日语版],它运行良好,并且很好地重写了我的 URL,但是当我插入日语数据时,它没有重写我的 URL 并得到 [错误请求错误]。
注意如果网站数据是英文的,运行良好。
更新
这是我的可重写 webconfig 代码的示例
<rewrite url="~/Seightseeing/(.+)/(.+).aspx" to="~/ExcursionsDetails.aspx?packageId=$1"/>
<rewrite url="~/LocalExperience/(.+)/(.+).aspx" to="~/ExcursionsDetails.aspx?packageId=$1"/>
<rewrite url="~/ShoreExcursions/(.+)/(.+).aspx" to="~/ExcursionsDetails.aspx?packageId=$1"/>
我认为 [Bad Request] 错误的原因是 Url 可能有特殊字符,尽管 GenerateURLMethod 包含清除特殊字符的一部分我在下面发布了方法
public static string GenerateURL(object Title, object strId)
{
string strTitle = Title.ToString();
#region Generate SEO Friendly URL based on Title
//Trim Start and End Spaces.
strTitle = strTitle.Trim();
//Trim "-" Hyphen
strTitle = strTitle.Trim('-');
strTitle = strTitle.ToLower();
char[] chars = @"$%#@!*?;:~`+=()[]{}|\'<>,/^&"".".ToCharArray();
strTitle = strTitle.Replace("c#", "C-Sharp");
strTitle = strTitle.Replace("vb.net", "VB-Net");
strTitle = strTitle.Replace("asp.net", "Asp-Net");
//Replace . with - hyphen
strTitle = strTitle.Replace(".", "-");
//Replace Special-Characters
for (int i = 0; i < chars.Length; i++)
{
string strChar = chars.GetValue(i).ToString();
if (strTitle.Contains(strChar))
{
strTitle = strTitle.Replace(strChar, string.Empty);
}
}
//Replace all spaces with one "-" hyphen
strTitle = strTitle.Replace(" ", "-");
//Replace multiple "-" hyphen with single "-" hyphen.
strTitle = strTitle.Replace("--", "-");
strTitle = strTitle.Replace("---", "-");
strTitle = strTitle.Replace("----", "-");
strTitle = strTitle.Replace("-----", "-");
strTitle = strTitle.Replace("----", "-");
strTitle = strTitle.Replace("---", "-");
strTitle = strTitle.Replace("--", "-");
//Run the code again...
//Trim Start and End Spaces.
strTitle = strTitle.Trim();
//Trim "-" Hyphen
strTitle = strTitle.Trim('-');
#endregion
//Append ID at the end of SEO Friendly URL
strTitle = "~/Seightseeing/" + strId + "/" + strTitle + ".aspx";
return strTitle;
}
我无法从您提供的代码中判断出什么问题。 您使用的是哪个 URL 重写模块? 您是否检查了 GenerateURL 方法(Title、strId)的输入参数以验证传入的值是否正确? 我可以看到此方法生成无效的 URL,例如,如果您传入“http://xyz.com”, //Replace Special-Characters
下的代码将删除://
部分。
你确定你正确使用了模块吗? 你在 web.config ( <rewrite url="~/Seightseeing/(.+)/(.+).aspx"...>
)中定义了重写模板,这对我来说似乎很奇怪,然后在//Append ID at the end of SEO Friendly URL
GenerateURL方法。
另外,我注意到//Replace multiple "-" hyphen with single "-" hyphen
下的代码看起来很有趣。 这是一个更优雅的版本:
while (strTitle.Contains("--"))
strTitle = strTitle.Replace("--", "-");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.