主题“XXX” 在应用程序或全局主题目录中找不到
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用 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.
在分配主题的 Page_PreInit 方法中,有几种方法可以处理它。 我所做的就是检查以确保该目录存在。 如果是的话,那就是我想要的主题。 如果没有,则使用我知道该目录存在的默认主题。
我通常存储在视图状态中,因此不必每次都重新检查,但如果您要动态更改主题,那么您可能不需要这样做。
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.
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.
如果用户使用您的主题进行重命名/删除,您必须确保更改用户的主题首选项。 如果重命名,则相应地重命名,如果删除,则更改为默认主题。当您将主题首选项存储在 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.