开发者

Japanese Characters with IIS7 URL Rewrite asp.net

Please help i had been built my website [the Japanese version] using a rewrite module it was work work well and rewrite my URL very well but when i had been inserted the Japanese data it not rewrite my URL and get [Bad request error].

Note If the the website data was English in working well.

Update

This is a sample of my rewritable webconfig code

<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"/>

I think the reason of the [Bad Request] error is the Url maybe have special character although the GenerateURLMethod contain apart of clearing the special character I posted the method below

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;
}


I can't tell what's wrong from the code you provided. Which URL rewriting module are you using? Did you check the input parameters to the GenerateURL method (Title, strId) to verify that correct values are being passed in? I could see this method generating an invalid URL, for example, if you pass in "http://xyz.com", the code under //Replace Special-Characters would strip out the :// part.

Are you sure you're using the module correctly? It seems strange to me that you define the rewrite template in web.config (<rewrite url="~/Seightseeing/(.+)/(.+).aspx"...>), and then define it again in the GenerateURL method under //Append ID at the end of SEO Friendly URL.

Also, I noticed that the code under //Replace multiple "-" hyphen with single "-" hyphen looks interesting. here's a more elegant version:

while (strTitle.Contains("--"))
    strTitle = strTitle.Replace("--", "-");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜