2015-03-08 91 views
0
protected void Application_BeginRequest(object sender, EventArgs e) 
    { 

     string file_path = Request.RawUrl.ToLower(); 
     char[] separator = new char[] { '/' }; 

     string[] parts = file_path.Split(separator, StringSplitOptions.RemoveEmptyEntries); 

     if (parts.Length > 0 && parts[0] == "de") 
     { 

      System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("de"); 

      Context.RewritePath("~/" + file_path.Substring(4), true); 
     } 
     else if (parts.Length > 0 && parts[0] == "en") 
     { 
      System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en"); 

      Context.RewritePath("~/" + file_path.Substring(4), true); 
     } 
     else 
     { 
      System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en"); 
     } 

    } 

我用我的WebForms網站驗證碼才能使用的https://example.com/en/some/url語言本地化URL重寫刪除默認頁面功能

更多的搜索引擎友好的結構,而不是我之前預期的基於cookie的系統使用。

但是,現在我已經完成了這項工作,如果我不使用指定文件的URL,則會出現500錯誤。例如,https://example.com/en/不起作用,但是/ en/default會做什麼 - 處理這個問題的正確方法是什麼?

+0

請發佈您用於重寫URL的代碼。我沒有看到任何人可以在沒有看到代碼的情況下幫助你。 – NightOwl888 2015-03-09 05:20:15

+0

它上面可... ,說 保護無效的Application_BeginRequest位(對象發件人,EventArgs的) – 2015-03-10 14:04:26

+0

我只能想法通過視頻網址[ASPNET(HTTP周圍做其他的方式類似的事情:// www.asp.net/web-forms/videos/how-do-i/how-do-i-create-a-multi-lingual-site-with-localization) – Kris1 2015-04-16 10:42:53

回答