2011-06-14 39 views
1

請幫助我建立了我的網站[日文版]使用重寫模塊它工作得很好,並很好地重寫我的網址,但是當我插入日本數據時不重寫我的網址並得到[錯誤的請求錯誤]。日本字符與IIS7 URL重寫asp.net

備註如果網站數據是英文的,運行良好。

更新

這是我重寫的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"/> 

我認爲[錯誤的請求]的原因錯誤是URL也許有特殊字符雖然GenerateURL方法包含除了清除特殊字符 我發佈了下面的方法

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

你可以顯示你的重寫規則和例子嗎? – matk 2011-06-14 07:57:10

回答

0

我不能說你提供的代碼有什麼問題。你正在使用哪個URL重寫模塊?您是否檢查了GenerateURL方法(Title,strId)的輸入參數以驗證傳入的值是否正確?例如,如果您傳入「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("--", "-");