请帮助我已经建立了我的网站,日文版本,使用重写模块,它工作良好,重写我的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"/>我认为错误请求错误的原因是网址可能有特殊字符,尽管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;
}发布于 2011-06-14 11:36:17
我无法从你提供的代码中看出出了什么问题。您正在使用哪个URL重写模块?您是否检查了GenerateURL方法(标题、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("--", "-");https://stackoverflow.com/questions/6338032
复制相似问题