Theme XXX cannot be found in application directories or global themes

My asp.net site allows users to select the theme they need from the list created in the app_themes folder. From time to time, topics are renamed or deleted. Any user who selects the name of a deleted topic (it is stored in a cookie) will receive an 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 catch and handle this exception?

+7
themes
source share
3 answers

In the Page_PreInit method, where you assign topics, there are several ways to handle this. I am doing a check to make sure the directory exists. If so, then this is the topic I want. If this is not the case, use the 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 a view, so I don’t need to double-check every time, but if you change themes on the fly, you probably don't need to do this.

+2
source share

if you use cookies to store a user-selected theme and you receive an error message “xxx'theme” not found in the local or global directory, then make sure your cookie name does not match with another cookie name.

+3
source share

You need to make sure that you change the user theme preference if they use your theme to rename / delete. If renamed, rename accordingly; if deleted, change the default theme. When you keep the theme preference inside cookies, you will need to check them and make changes to user access.

0
source share

All Articles