开发者

Setting the Page.Theme in code makes the css files get linked to twice

In ASP.NET we have until now only had one theme, which was specified in the web.config. I recently started switching the Theme in the base page PreInit based on the Request.Url.Host value, say domain1.com was the original & we are now adding domain2.com with it开发者_Go百科s own style. Since doing this all the <link rel="stylesheet...> tags are injected twice into the page. The domain1 ones which were always injected at the very start of the <head> section, then the <title> tag, followed by all the stylesheet link tags again for which ever theme is explicitly set in the page PreInit.

As I understand it ASP.NET will include every css file in the themes folder automatically, at which event in the page lifecycle does it do this?


Ok, so I found the issue, we were attaching to the PreInit event handler rather than overriding the OnPreInit method on the page, which resulted in this weird side effect. Seems that .NET does some funky magic in the preinit to setup the theme default from the web.config which doesn't get fully overridden if you set the Theme property in the event handler rather than in the method. Most likely this is due to the fact that events don't have a guaranteed order of execution so it's happening either too early or too late.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜