使用 ASP.Net 母版页和主题从内部文件夹引用 favicon
我的新 ASP.Net 页面上存在以下情况:
- 我正在使用母版页
- 我正在使用主题
- 我的页面位于单独的文件夹中
我需要根据当前主题从我的母版页引用网站图标。
不幸的是, ~App_Themes/Basic/Images/favicon.ico 路径解析为 http:// example.com/folder/App_Themes/Basic/Images/favicon.ico。
如何从以下不同位置的页面使用的母版页统一引用位于 App_Themes/Basic/Images/favicon.ico 路径中的 favicon.ico:
- ~/Home.aspx
- ~/Secure/Dashboard.aspx
- ~/Accounts/登录.aspx
I have the following situation on my new ASP.Net page:
- I am using a master page
- I am using themes
- I have pages in separate folders
I need to reference a favicon from my master page based on the current theme.
Unfortunately the ~App_Themes/Basic/Images/favicon.ico path resolves to http://example.com/folder/App_Themes/Basic/Images/favicon.ico.
How can I uniformly refer to my favicon.ico located in the App_Themes/Basic/Images/favicon.ico path from master page used by the following differently located pages:
- ~/Home.aspx
- ~/Secure/Dashboard.aspx
- ~/Accounts/Login.aspx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,ASP.NET 主题仅限于外观文件和 CSS 文件,其中所有图像均从 CSS 文件引用。在这种情况下,图像的路径是相对于 CSS 文件的。
如果您需要页面中当前主题文件夹内的文件路径,可以使用 Page.Theme 属性与 Page.ResolveUrl() 方法:
如果您想在
元素中使用该方法,您只需放置代码即可位于
href
属性内。除非您有,在这种情况下 ASP.NET 可能会抛出 HttpException:
可以通过将
元素放入
控件中来修复此问题:Usually ASP.NET themes are limited to skin files and CSS files with all images referenced from the CSS file. In that scenario, the paths to images are relative from the CSS file.
If you need a path to a file inside the current theme's folder relative from a page, you can use the Page.Theme property combined with the Page.ResolveUrl() method:
If you want to use that in a
<link rel="shortcut icon">
element you can just put the code above inside thehref
attribute. Unless you have a<head runat="server">
, in which case ASP.NET may throw an HttpException:This can be fixed by putting the
<link>
element inside an<asp:PlaceHolder>
control: