2010-07-12 32 views

回答

3

如果您使用的是内置的主题和全球化的支持,你可以使用一个HTTP模块:(未经测试)

public class PageModule : IHttpModule 
{ 


public void Dispose() 
{ 
} 


public void Init(System.Web.HttpApplication context) 
{ 
    context.PreRequestHandlerExecute += Application_PreRequestHandlerExecute; 

} 

public void Application_PreRequestHandlerExecute(object sender, EventArgs e) 
{ 
    //Adds a handler that executes on every page request 
    HttpApplication application = default(HttpApplication); 
    application = (HttpApplication)sender; 

    Page page = application.Context.CurrentHandler as Page; 

    if ((page != null)) 
     page.PreInit += Page_PreInit; 

} 


public void Page_PreInit(object sender, EventArgs e) 
{ 
    //If current context has no session then abort 
    if (HttpContext.Current.Session == null) 
     return; 

    //Get current page context 
    Page page = (Page)sender; 

    switch (page.Culture) { 
     case "en-US": 
      page.Theme = "en-USTheme"; 
      break; 
     case "fr-FR": 
      page.Theme = "fr-FRTheme"; 
      break; 
     default: 
      page.Theme = "DefaultTheme"; 
      break; 
    } 

} 

} 
+0

文化特定代码不可见。我们需要向下滚动代码文本框来查看切换(page.Culture)。 – 2011-06-19 01:29:14

1

您可以将所选语言写入Cookie中。然后在您的母版页检查保存在cookie中的值并分配正确的样式表。

+0

我存储在会话我的文化信息,但我不知道如何加载当文化发生变化时,不同的css文件 – 2010-07-12 17:46:51

+0

@ WingMan20-10文化信息最佳存储位置在URL中,如www.abc.com/en-us /../ ..' – shashwat 2013-06-01 07:53:27