2015-03-08 120 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

回答