默认 ASP.NET 主题
是否可以为 ASP.NET 网站创建默认主题?
例如,如果我有一个名为 “Default”
的主题,并且我选择了一个名为 “NewTheme”
的主题,并且我引用了一个 中不存在的文件>“NewTheme”
但确实存在于“Default”
主题中,例如:
<asp:image id="img" runat="server" ImageUrl="~/Images/image.jpg" />
可以从“/App_Themes/Default/Images/image.jpg”中获取吗
如果不存在在“/App_Themes/NewTheme/Images/image.jpg”
?
此外,如果“NewTheme”中不存在CSS类,但在“Default”中存在,那么它可以采用“Default”吗?事实上,我认为如果它首先采用所有默认样式,然后覆盖任何与“NewTheme”发生冲突的样式,效果会更好。
我知道全局引用的工作方式与此类似,因为如果我选择了“es”本地化,并且 webreference.resx.es
文件中不存在密钥,但它存在于webreference.resx
,然后它将从那里获取值。
我认为这对于 ASP.NET 主题来说是重要的功能,因为我可以想象不同的主题仅更改了某些图像和某些样式。我无法想象每个主题的每个图像和每个风格总是完全不同。因此,如果没有此功能,它将成为重复样式/图像的情况,我不喜欢这种情况(出于明显的原因!)。
Is it possible to create a default theme for an ASP.NET Website?
For example, If I had a theme called "Default"
, and ive selected a theme called "NewTheme"
and I referenced a file which doesn't exist in the "NewTheme"
but does exist in the "Default"
theme like:
<asp:image id="img" runat="server" ImageUrl="~/Images/image.jpg" />
Could that then be taken from "/App_Themes/Default/Images/image.jpg"
if it does not exist at "/App_Themes/NewTheme/Images/image.jpg"
?
Furthermore if a CSS class didn't exist in "NewTheme", but it did in "Default", then could it take the "Default"? In fact, I think it would be better if it first took all the default styles, and then overrides any that "NewTheme" have which clashes.
I know Global References work similar to this because if ive selected "es"
localization, and a key doesn't exist in the webreference.resx.es
file but it does in webreference.resx
, then itll take the value from there.
I think this would be important functionality for ASP.NET Themes as I can imagine different themes only having certain images changed, and certain styles changed. I can't imagine every image and every style always being totally different for each Theme. And therefore without this functionality, its going to be a case of duplicating styles/images, which I'm not a fan of (for obvious reasons!).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ASP.NET 不支持您所描述的默认主题。有常规的
Themes
和StyleSheetTheme
,但在页面请求级别动态更改它们比单个控件或静态文件更有用。您可以使用 URL 重写或路由为静态文件编写自己的主题版本 - 但它不再是真正的主题。
对于像
这样的控件,您可以覆盖它们并根据“主题”文件夹的某些层次结构中存在的文件来修改ImageUrl
等属性。然后使用标记映射将该控件的所有实例替换为新控件,而不需要任何标记更改。FWIW,Global.asax 中的
BeginRequest
事件仅针对 IIS 中的动态文件调用(Cassini 也将其称为静态文件)。要在 IIS 中支持静态,您需要一个HttpModule
,并且还需要将 IIS 配置为在集成模式下运行。Default themes as you describe aren't supported by ASP.NET. There are regular
Themes
andStyleSheetTheme
s, but changing them dynamically is more useful at the Page request level than for individual Controls or static files.You can code up your own version of themes for static files using URL rewriting or routing -- but then it's not really Themes any more.
For controls like
<asp:Image>
, you could override them and modify properties such asImageUrl
based on which files exist in some hierarchy of "theme" folders. Then use tag mapping to replace all instances of that control with the new one, without requiring any markup changes.FWIW, the
BeginRequest
event in Global.asax is only invoked for dynamic files in IIS (Cassini calls it for statics, too). To support statics in IIS, you'll need anHttpModule
, and you'll also need to configure IIS to run in Integrated mode.此功能未内置于 ASP.NET 中。不过,您可以相当轻松地实现它:
HttpRequest.PhysicalPath
处的文件是否存在。HttpContext.RewritePath
并将请求 URL 中的“NewTheme”替换为“Default”。This functionality isn't built into ASP.NET. Nevertheless, you could implement it fairly easily:
HttpApplication.BeginRequest
event in Global.asax or in a custom HTTP module.HttpRequest.PhysicalPath
exists.HttpContext.RewritePath
and replace "NewTheme" in the request URL with "Default".