为什么我的 Theme.Master 找不到它的 Site.css?
<link href="Site.css" rel="stylesheet" type="text/css" />
这在我的本地计算机上的 Theme.Master (Views/Themes/Blue/Theme.Master) 上工作得很好,但在其最终主页的托管提供商中却不起作用。 如果 css 位于 Content 文件夹及其任何子文件夹中,则 Theme.Master 可以找到该 css,但如果 css 与 Theme.Master 位于同一文件夹中则无法找到。
<link href="Site.css" rel="stylesheet" type="text/css" />
This works fine from Theme.Master (Views/Themes/Blue/Theme.Master) on my local machine, but not from the hosted provider of its final home. The Theme.Master can find the css if the css is in the Content folder, in any subfolders of the Content folder, but not if the css is in the same folder as the Theme.Master.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您必须使用相对文件引用。 试试这个:
......这应该可以解决问题。
编辑
既然您评论说这不起作用,我就查找从哪里找到解决方案。 我从 Lance Fisher 那里得到它 此博客文章。 如果还没有弄清楚(因为它正在讨论 java 脚本文件),您还可以查看 此处位于之前回答过的类似问题。 希望有帮助!
You've to use relative file references. Try this:
...and that should solve the problem.
Edit
Since you commented that this didn't work, I looked up where I found my solution from. I got it from Lance Fisher in this blog post. In case that doesn't clear it up (since it is talking about java script files), you can also look here at a similar question that was answered previously. Hope that helps!
您对 Nick 的回答的评论意味着您正在尝试将 .css 文件放在与 ~/Views/ 文件夹树下的 Theme.Master 文件相同的文件夹中。 你不能这样做。 ~/Views/ 树配置为阻止来自 Web 浏览器的所有 HTTP 请求。
您需要将 .css 文件放在可访问的位置。 ~/Content/ 文件夹树是放置 .css 文件的传统位置。 如果您将 .css 文件移到那里,然后按照 Nick 的建议使用它,它将起作用:
根据记录,它在 Views 文件夹中不起作用,因为 web.config 文件中的这些指令(注意,有一个 web .config 文件直接位于 Views 文件夹中)。 这仅供参考。 我不建议你尝试搞乱这些,因为它们的存在通常有充分的理由:
Your comment on Nick's answer implies that you are trying to put a .css file in the same folder as the Theme.Master file that is under the ~/Views/ folder tree. You can't do this. The ~/Views/ tree is configured to block all HTTP requests from the web browser.
You need to put your .css file in an accessible location. The ~/Content/ folder tree is the traditional place to put a .css file. If you move your .css file there and then use this as Nick suggested, it will work:
For the record, it doesn't work in the Views folder because of these directives in the web.config file (note, there is a web.config file directly in the Views folder). This is just FYI. I don't advise you try to mess with these as they are there for generally good reasons:
您是否尝试过使用根路径? 例如:
或者
如果您的样式表不在网站的根目录中。
Have you tried using a rooted path? Such as:
or
if your style sheet isn't on the root of your site.
在托管提供商上,应用程序是否位于站点根目录中? 或者在子文件夹中? 您的开发环境在这方面与服务器上的设置匹配吗? 您可能需要确保您的工作相对于应用程序根目录 ~/
从根本上讲,这与相同的问题(使用脚本)类似 此处讨论。
On the hosted provider, is the app in the site root? or in a sub-folder? Does your development environment match the setup at the server in this respect? You may need to ensure you work relative to the app root, ~/
Fundamentally, this is similar to the same problem (with scripts) discussed here.