主题“XXX” 在应用程序或全局主题目录中找不到

发布于 2024-07-25 21:23:21 字数 787 浏览 3 评论 0原文

我的 asp.net 站点允许用户从 app_themes 文件夹生成的列表中选择他们想要的主题。 有时,主题会被重命名或删除。 任何选择已删除主题名称(存储在 cookie 中)的用户都会收到异常:

Theme 'XXX' cannot be found in the application or global theme directories
Stack Trace: 
[HttpException (0x80004005): Theme 'test' cannot be found in the application or global theme directories.]
   System.Web.Compilation.ThemeDirectoryCompiler.GetThemeBuildResultType(String themeName) +920
   System.Web.Compilation.ThemeDirectoryCompiler.GetThemeBuildResultType(HttpContext context, String themeName) +73
   System.Web.UI.Page.InitializeThemes() +8699455
   System.Web.UI.Page.PerformPreInit() +38
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +282

捕获和处理此异常的最佳位置在哪里?

My asp.net site allows users to pick the theme they want from a list generated from the app_themes folder. From time to time, themes are renamed or removed. Any user who has selected a deleted theme name (it is stored in a cookie) will get the exception:

Theme 'XXX' cannot be found in the application or global theme directories
Stack Trace: 
[HttpException (0x80004005): Theme 'test' cannot be found in the application or global theme directories.]
   System.Web.Compilation.ThemeDirectoryCompiler.GetThemeBuildResultType(String themeName) +920
   System.Web.Compilation.ThemeDirectoryCompiler.GetThemeBuildResultType(HttpContext context, String themeName) +73
   System.Web.UI.Page.InitializeThemes() +8699455
   System.Web.UI.Page.PerformPreInit() +38
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +282

Where is the best place to trap and handle this exception?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眉黛浅 2024-08-01 21:23:21

如果您使用 cookie 来存储用户选择的主题,并且收到错误“xxx”,在本地或全局目录中找不到主题,请确保您的 cookie 名称与其他 cookie 名称不同。

if you use cookies to store user selected theme and you get error 'xxx'theme not found in local or global directory, then make sure that your cookie name is not same with another cookie name.

梦里寻她 2024-08-01 21:23:21

在分配主题的 Page_PreInit 方法中,有几种方法可以处理它。 我所做的就是检查以确保该目录存在。 如果是的话,那就是我想要的主题。 如果没有,则使用我知道该目录存在的默认主题。

void Page_PreInit(object sender, EventArgs e)
{
    if (ViewState["PageTheme"] == null)
    {
        if (!Directory.Exists("~/App_Themes/THEMENAME_TO_LOOK_FOR"))
        {
            Theme = "DEFAULT_THEME"
        } 
        else 
        {
            Theme = "THEMENAME_TO_LOOK_FOR";
        }
        ViewState["PageTheme"] = Theme;
    } 
    else 
    {
        Theme = ViewState["PageTheme"].ToString();
    }
}

我通常存储在视图状态中,因此不必每次都重新检查,但如果您要动态更改主题,那么您可能不需要这样做。

In the Page_PreInit method where you assign themes, there's a couple of ways to deal with it. What I do is check to make sure that the directory exists. If it does, then that's the theme I want. If it doesn't, then use a default theme where I know the directory exists.

void Page_PreInit(object sender, EventArgs e)
{
    if (ViewState["PageTheme"] == null)
    {
        if (!Directory.Exists("~/App_Themes/THEMENAME_TO_LOOK_FOR"))
        {
            Theme = "DEFAULT_THEME"
        } 
        else 
        {
            Theme = "THEMENAME_TO_LOOK_FOR";
        }
        ViewState["PageTheme"] = Theme;
    } 
    else 
    {
        Theme = ViewState["PageTheme"].ToString();
    }
}

I usually store in the viewstate so I don't have to recheck every time but if you're changing themes on-the-fly, then you'll probably need to not do that.

潇烟暮雨 2024-08-01 21:23:21

如果用户使用您的主题进行重命名/删除,您必须确保更改用户的主题首选项。 如果重命名,则相应地重命名,如果删除,则更改为默认主题。当您将主题首选项存储在 cookie 中时,您必须检查它们并在用户访问权限上进行更改。

You have to make sure that you change users' theme preference if they use your theme to be renamed/deleted. If renamed, then rename accordingly, if deleted, change to default theme.As you store theme preference inside cookies you'll have to check them and make the change on user access.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文