为什么我的 Theme.Master 找不到它的 Site.css?

发布于 2024-07-17 09:07:55 字数 276 浏览 6 评论 0原文

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不交电费瞎发啥光 2024-07-24 09:07:55

您必须使用相对文件引用。 试试这个:

<link href="<%= Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css" />

......这应该可以解决问题。

编辑
既然您评论说这不起作用,我就查找从哪里找到解决方案。 我从 Lance Fisher 那里得到它 此博客文章。 如果还没有弄清楚(因为它正在讨论 java 脚本文件),您还可以查看 此处位于之前回答过的类似问题。 希望有帮助!

You've to use relative file references. Try this:

<link href="<%= Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css" />

...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!

柠檬 2024-07-24 09:07:55

您对 Nick 的回答的评论意味着您正在尝试将 .css 文件放在与 ~/Views/ 文件夹树下的 Theme.Master 文件相同的文件夹中。 你不能这样做。 ~/Views/ 树配置为阻止来自 Web 浏览器的所有 HTTP 请求。

您需要将 .css 文件放在可访问的位置。 ~/Content/ 文件夹树是放置 .css 文件的传统位置。 如果您将 .css 文件移到那里,然后按照 Nick 的建议使用它,它将起作用:

<link href="<%= Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css" />

根据记录,它在 Views 文件夹中不起作用,因为 web.config 文件中的这些指令(注意,有一个 web .config 文件直接位于 Views 文件夹中)。 这仅供参考。 我不建议你尝试搞乱这些,因为它们的存在通常有充分的理由:

<!-- for IIS6 -->
<httpHandlers>
  <add path="*" verb="*"
      type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>

<!-- for IIS7 -->
<handlers>
  <remove name="BlockViewHandler"/>
  <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
</handlers>

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:

<link href="<%= Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css" />

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:

<!-- for IIS6 -->
<httpHandlers>
  <add path="*" verb="*"
      type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>

<!-- for IIS7 -->
<handlers>
  <remove name="BlockViewHandler"/>
  <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
</handlers>
北城挽邺 2024-07-24 09:07:55

您是否尝试过使用根路径? 例如:

<link href="/Site.css" rel="stylesheet" type="text/css" />

或者

<link href="/style/Site.css" rel="stylesheet" type="text/css" />

如果您的样式表不在网站的根目录中。

Have you tried using a rooted path? Such as:

<link href="/Site.css" rel="stylesheet" type="text/css" />

or

<link href="/style/Site.css" rel="stylesheet" type="text/css" />

if your style sheet isn't on the root of your site.

千年*琉璃梦 2024-07-24 09:07:55

在托管提供商上,应用程序是否位于站点根目录中? 或者在子文件夹中? 您的开发环境在这方面与服务器上的设置匹配吗? 您可能需要确保您的工作相对于应用程序根目录 ~/

从根本上讲,这与相同的问题(使用脚本)类似 此处讨论

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文