App_Themes 在初始加载时未加载
我有一个应用程序,不同的用户可以通过单个门户登录来登录。当他们登录时 中,如果他们属于超过 1 个公司,他们必须选择他们所属的公司。如果该公司有自定义主题,则主题将会更改。
我的应用程序的每个页面都继承一个“CustomPage”类
以下是自定义页面的代码:
public class CustomPage : Page
{
protected void Page_PreInit(object sender, EventArgs e)
{
if (Globals.Company != null && Directory.Exists(Page.MapPath("~/App_Themes/" + Globals.Company.CompanyName)))
{
Page.Theme = Globals.Company.CompanyName;
}
else
{
Page.Theme = "Default";
}
}
}
当客户属于超过 1 个公司,并且他们选择自己所属的公司时,主题加载得很好。
所以,我遇到的问题是:
如果它们只属于 1 个公司,则会自动选择该公司,但主题不会立即加载。但是,如果我刷新页面,主题加载得很好。即使默认主题也不会加载。在我刷新之前,该页面根本没有 CSS。
我什至查看源代码并查找我的 css 名称,但它们不在那里。我刷新并做了同样的事情,它们就在那里。
我没有使用表单身份验证,并且 Web 配置中的默认主题是“默认”,您
<pages theme="Default">
对可能发生的情况有什么想法吗?如果您需要澄清任何事情,请询问。
谢谢!
I have an application where different users can log in via a single portal login. When they log
in, if they belong to more than 1 company they have to select the company they belong to. The theme will change if there is a custom theme for that company.
Each page my application has inherits a "CustomPage" class
Here is the code for the custom page:
public class CustomPage : Page
{
protected void Page_PreInit(object sender, EventArgs e)
{
if (Globals.Company != null && Directory.Exists(Page.MapPath("~/App_Themes/" + Globals.Company.CompanyName)))
{
Page.Theme = Globals.Company.CompanyName;
}
else
{
Page.Theme = "Default";
}
}
}
When the customer belongs to more than 1 company, and they select the company they belong to, the theme loads just fine.
So, the problem I am having is this:
If they belong to just 1 company, the company is automatically selected but the theme does not load right away. However, if I refresh the page, the theme loads just fine. Even the default theme will not load. The page has no css at all until I refresh.
I even view source and look for my css names and they are not there. I refresh and do the same thing, and they are there.
I am not using forms authentication and the default theme in the web config is "Default"
<pages theme="Default">
Any thoughts to what might be going on? If you need clarification on anything, please ask.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了问题。在登录期间设置公司信息之前调用 Page_PreInit。
因此,在用户登录后,我就在此处调用逻辑来检查公司详细信息与母版页加载中的情况。
I found the problem. The Page_PreInit was being called before the Company information was being set during login.
So after the user logged in, that is where I called the logic to check the company details versus in the master page load.