Url rewriting 有一个多语言的网站,需要显示语言的查询字符串,包括完整的代码

Url rewriting 有一个多语言的网站,需要显示语言的查询字符串,包括完整的代码,url-rewriting,asp.net,iis-7,internationalization,Url Rewriting,Asp.net,Iis 7,Internationalization,我有一个多语言的公司网站(9种语言——Visual Studio 2010/VB/ASP.NET 4.0)。我遵循了一个教程,介绍了如何使客户端可以单击一个标志,页面将以该文化的语言显示。它在这方面非常有效网站中的每个页面都设置为继承BasePage.vb。我的App_GlobalResources文件夹中有9个资源(.resx)文件 问题: 如果终端用户打开了,例如domain/default.aspx,他们单击德语标志,文本将切换为德语,并将持续整个会话。那很好。但是URL保持不变--dom

我有一个多语言的公司网站(9种语言——Visual Studio 2010/VB/ASP.NET 4.0)。我遵循了一个教程,介绍了如何使客户端可以单击一个标志,页面将以该文化的语言显示。它在这方面非常有效网站中的每个页面都设置为继承BasePage.vb。我的App_GlobalResources文件夹中有9个资源(.resx)文件

问题:

如果终端用户打开了,例如domain/default.aspx,他们单击德语标志,文本将切换为德语,并将持续整个会话。那很好。但是URL保持不变--domain/default.aspx。即使网页上的文本已更改,也不建议在URL中使用语言

有人向我建议,当客户选择一种语言时,最好是这样,URL读作domain/default.aspx?lang=dedomain/de/default.aspx(首选)

我的问题:

我如何才能做到这一点?使用IIS7重写规则最简单吗?如果是,怎么做?我是否必须在我的代码隐藏中或在我的basepage.vb中编辑某些内容?在此方面的任何指导都将不胜感激

(附言——我知道这很长,但对于任何深入研究这一点的人来说,如果有必要的话,我会在下面列出我的编码)

---Homepage.master——只有两个例子。“de”调用LocalizedText.de.resx文件-------

-----------------BasePage.vb(应用程序代码文件夹中)-------------------

        Partial Public Class Homepage
      Inherits System.Web.UI.MasterPage
      Protected Sub Page_Load(sender As Object, e As EventArgs)
      End Sub

      Protected Sub RequestLanguageChange_Click(sender As Object, e As EventArgs)
          Dim senderLink As LinkButton = TryCast(sender, LinkButton)

          'store requested language as new culture in the session
       Session(Udev.MasterPageWithLocalization.Classes.Global.SESSION_KEY_CULTURE) = 
          senderLink.CommandArgument()

          'reload last requested page with new culture
          Server.Transfer(Request.Path)
      End Sub
  End Class
  Imports Microsoft.VisualBasic
  Imports System
  Imports System.Data
  Imports System.Configuration
  Imports System.Globalization
  Imports System.Threading
  Imports System.Web
  Imports System.Web.Security
  Imports System.Web.UI
  Imports System.Web.UI.WebControls
  Imports System.Web.UI.WebControls.WebParts
  Imports System.Web.UI.HtmlControls

  Namespace Udev.MasterPageWithLocalization.Classes
      ''' <summary>
      ''' Custom base page used for all web forms.
      ''' </summary>
      Public Class BasePage
          Inherits Page

          Protected Overrides Sub InitializeCulture()
              'retrieve culture information from session
              Dim culture__1 As String =       
        Convert.ToString(Session([Global].SESSION_KEY_CULTURE))

              'check whether a culture is stored in the session
              If culture__1.Length > 0 Then
                  Culture = culture__1
              End If

              'set culture to current thread
              Thread.CurrentThread.CurrentCulture =   
      CultureInfo.CreateSpecificCulture(culture__1)
             Thread.CurrentThread.CurrentUICulture = New CultureInfo(culture__1)
              'call base class
              MyBase.InitializeCulture()
          End Sub
      End Class
  End Namespace
  Imports Microsoft.VisualBasic
  Imports System
  Imports System.Data
  Imports System.Configuration
  Imports System.Web
  Imports System.Web.Security
  Imports System.Web.UI
  Imports System.Web.UI.WebControls
  Imports System.Web.UI.WebControls.WebParts
  Imports System.Web.UI.HtmlControls

  Namespace Udev.MasterPageWithLocalization.Classes
      ''' <summary>
      ''' This class provides ISO definitions for all cultures that are supported by
         this application.
      ''' </summary>
      Public Structure Culture
          'German - Switzerland definition
          Public Const DE As String = "de"
          'English - Great Britain definition
          Public Const EN As String = "en"
      End Structure
  End Namespace
  Imports System
  Imports System.Data
  Imports System.Configuration
  Imports System.Web
  Imports System.Web.Security
  Imports System.Web.UI
  Imports System.Web.UI.WebControls
  Imports System.Web.UI.WebControls.WebParts
  Imports System.Web.UI.HtmlControls

  Namespace Udev.MasterPageWithLocalization.Classes
      ''' <summary>
      ''' Summary description for Global
      ''' </summary>
      Public Structure [Global]
          Public Const SESSION_KEY_CULTURE As String = "culture"
      End Structure
  End Namespace
导入Microsoft.VisualBasic
导入系统
导入系统数据
导入系统配置
进口系统.全球化
导入系统线程
导入系统.Web
导入System.Web.Security
导入System.Web.UI
导入System.Web.UI.WebControl
导入System.Web.UI.WebControl.WebParts
导入System.Web.UI.HTMLControl
命名空间Udev.MasterPageWithLocalization.Classes
''' 
''用于所有web表单的自定义基本页。
''' 
公共类基页
继承页面
受保护的覆盖子初始化文化()
'从会话检索区域性信息
Dim CURITY__1作为字符串=
Convert.ToString(会话([Global].Session\u KEY\u区域性))
'检查区域性是否存储在会话中
如果区域性长度1.Length>0,则
文化=文化1
如果结束
'将区域性设置为当前线程
Thread.CurrentThread.CurrentCulture=
CultureInfo.CreateSpecificCulture(文化1)
Thread.CurrentThread.CurrentUICulture=新的文化信息(文化1)
'调用基类
MyBase.InitializeCulture()
端接头
末级
结束命名空间
-------------Culture.vb(应用程序代码文件夹中)-------------------

        Partial Public Class Homepage
      Inherits System.Web.UI.MasterPage
      Protected Sub Page_Load(sender As Object, e As EventArgs)
      End Sub

      Protected Sub RequestLanguageChange_Click(sender As Object, e As EventArgs)
          Dim senderLink As LinkButton = TryCast(sender, LinkButton)

          'store requested language as new culture in the session
       Session(Udev.MasterPageWithLocalization.Classes.Global.SESSION_KEY_CULTURE) = 
          senderLink.CommandArgument()

          'reload last requested page with new culture
          Server.Transfer(Request.Path)
      End Sub
  End Class
  Imports Microsoft.VisualBasic
  Imports System
  Imports System.Data
  Imports System.Configuration
  Imports System.Globalization
  Imports System.Threading
  Imports System.Web
  Imports System.Web.Security
  Imports System.Web.UI
  Imports System.Web.UI.WebControls
  Imports System.Web.UI.WebControls.WebParts
  Imports System.Web.UI.HtmlControls

  Namespace Udev.MasterPageWithLocalization.Classes
      ''' <summary>
      ''' Custom base page used for all web forms.
      ''' </summary>
      Public Class BasePage
          Inherits Page

          Protected Overrides Sub InitializeCulture()
              'retrieve culture information from session
              Dim culture__1 As String =       
        Convert.ToString(Session([Global].SESSION_KEY_CULTURE))

              'check whether a culture is stored in the session
              If culture__1.Length > 0 Then
                  Culture = culture__1
              End If

              'set culture to current thread
              Thread.CurrentThread.CurrentCulture =   
      CultureInfo.CreateSpecificCulture(culture__1)
             Thread.CurrentThread.CurrentUICulture = New CultureInfo(culture__1)
              'call base class
              MyBase.InitializeCulture()
          End Sub
      End Class
  End Namespace
  Imports Microsoft.VisualBasic
  Imports System
  Imports System.Data
  Imports System.Configuration
  Imports System.Web
  Imports System.Web.Security
  Imports System.Web.UI
  Imports System.Web.UI.WebControls
  Imports System.Web.UI.WebControls.WebParts
  Imports System.Web.UI.HtmlControls

  Namespace Udev.MasterPageWithLocalization.Classes
      ''' <summary>
      ''' This class provides ISO definitions for all cultures that are supported by
         this application.
      ''' </summary>
      Public Structure Culture
          'German - Switzerland definition
          Public Const DE As String = "de"
          'English - Great Britain definition
          Public Const EN As String = "en"
      End Structure
  End Namespace
  Imports System
  Imports System.Data
  Imports System.Configuration
  Imports System.Web
  Imports System.Web.Security
  Imports System.Web.UI
  Imports System.Web.UI.WebControls
  Imports System.Web.UI.WebControls.WebParts
  Imports System.Web.UI.HtmlControls

  Namespace Udev.MasterPageWithLocalization.Classes
      ''' <summary>
      ''' Summary description for Global
      ''' </summary>
      Public Structure [Global]
          Public Const SESSION_KEY_CULTURE As String = "culture"
      End Structure
  End Namespace
导入Microsoft.VisualBasic
导入系统
导入系统数据
导入系统配置
导入系统.Web
导入System.Web.Security
导入System.Web.UI
导入System.Web.UI.WebControl
导入System.Web.UI.WebControl.WebParts
导入System.Web.UI.HTMLControl
命名空间Udev.MasterPageWithLocalization.Classes
''' 
''此类为受支持的所有区域性提供ISO定义
这个应用程序。
''' 
公共结构文化
"德国-瑞士定义
公共常数DE As String=“DE”
英国-大不列颠定义
Public Const EN As String=“EN”
端部结构
结束命名空间
--------------Global.vb(应用程序代码文件夹中)--------------------------

        Partial Public Class Homepage
      Inherits System.Web.UI.MasterPage
      Protected Sub Page_Load(sender As Object, e As EventArgs)
      End Sub

      Protected Sub RequestLanguageChange_Click(sender As Object, e As EventArgs)
          Dim senderLink As LinkButton = TryCast(sender, LinkButton)

          'store requested language as new culture in the session
       Session(Udev.MasterPageWithLocalization.Classes.Global.SESSION_KEY_CULTURE) = 
          senderLink.CommandArgument()

          'reload last requested page with new culture
          Server.Transfer(Request.Path)
      End Sub
  End Class
  Imports Microsoft.VisualBasic
  Imports System
  Imports System.Data
  Imports System.Configuration
  Imports System.Globalization
  Imports System.Threading
  Imports System.Web
  Imports System.Web.Security
  Imports System.Web.UI
  Imports System.Web.UI.WebControls
  Imports System.Web.UI.WebControls.WebParts
  Imports System.Web.UI.HtmlControls

  Namespace Udev.MasterPageWithLocalization.Classes
      ''' <summary>
      ''' Custom base page used for all web forms.
      ''' </summary>
      Public Class BasePage
          Inherits Page

          Protected Overrides Sub InitializeCulture()
              'retrieve culture information from session
              Dim culture__1 As String =       
        Convert.ToString(Session([Global].SESSION_KEY_CULTURE))

              'check whether a culture is stored in the session
              If culture__1.Length > 0 Then
                  Culture = culture__1
              End If

              'set culture to current thread
              Thread.CurrentThread.CurrentCulture =   
      CultureInfo.CreateSpecificCulture(culture__1)
             Thread.CurrentThread.CurrentUICulture = New CultureInfo(culture__1)
              'call base class
              MyBase.InitializeCulture()
          End Sub
      End Class
  End Namespace
  Imports Microsoft.VisualBasic
  Imports System
  Imports System.Data
  Imports System.Configuration
  Imports System.Web
  Imports System.Web.Security
  Imports System.Web.UI
  Imports System.Web.UI.WebControls
  Imports System.Web.UI.WebControls.WebParts
  Imports System.Web.UI.HtmlControls

  Namespace Udev.MasterPageWithLocalization.Classes
      ''' <summary>
      ''' This class provides ISO definitions for all cultures that are supported by
         this application.
      ''' </summary>
      Public Structure Culture
          'German - Switzerland definition
          Public Const DE As String = "de"
          'English - Great Britain definition
          Public Const EN As String = "en"
      End Structure
  End Namespace
  Imports System
  Imports System.Data
  Imports System.Configuration
  Imports System.Web
  Imports System.Web.Security
  Imports System.Web.UI
  Imports System.Web.UI.WebControls
  Imports System.Web.UI.WebControls.WebParts
  Imports System.Web.UI.HtmlControls

  Namespace Udev.MasterPageWithLocalization.Classes
      ''' <summary>
      ''' Summary description for Global
      ''' </summary>
      Public Structure [Global]
          Public Const SESSION_KEY_CULTURE As String = "culture"
      End Structure
  End Namespace
导入系统
导入系统数据
导入系统配置
导入系统.Web
导入System.Web.Security
导入System.Web.UI
导入System.Web.UI.WebControl
导入System.Web.UI.WebControl.WebParts
导入System.Web.UI.HTMLControl
命名空间Udev.MasterPageWithLocalization.Classes
''' 
''全球业务的摘要说明
''' 
公共结构[全球]
Public Const SESSION\u KEY\u CULTURE为String=“CULTURE”
端部结构
结束命名空间