问题描述
||
请帮助我使用重写模块构建了我的网站[日语版],它可以正常工作并且很好地重写了我的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]错误的原因是网址可能具有特殊字符,尽管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(\"--\",\"-\");
//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 \”,则ѭ2under下的代码将去除
://
部分。
您确定使用正确吗?在Web.config(web4 web)中定义重写模板,然后在//Append ID at the end of SEO Friendly URL
下的GenerateURL方法中再次定义它,这对我来说似乎很奇怪。
另外,我注意到//Replace multiple \"-\" hyphen with single \"-\" hyphen
下的代码看起来很有趣。这是一个更优雅的版本:
while (strTitle.Contains(\"--\"))
strTitle = strTitle.Replace(\"--\",\"-\");