gpt4 book ai didi

asp.net - 加载不同的 CSS 以进行站点本地化

转载 作者:行者123 更新时间:2023-12-02 17:11:38 24 4
gpt4 key购买 nike

我需要根据用户选择的语言加载不同的css文件。我只需要在我的母版页中执行此操作。

最佳答案

如果您使用内置主题和全局化支持,您可以使用 httpModule:(未经测试)

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

}

}

关于asp.net - 加载不同的 CSS 以进行站点本地化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3230576/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com