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

时间:2021-01-02 11:25:15
<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.

这可以在我的本地机器上的Theme.Master(Views / Themes / Blue / Theme.Master)中正常工作,但不能从其最终主页的托管提供商处理。如果css位于Content文件夹中的Content文件夹的任何子文件夹中,Theme.Master可以找到css,但如果css与Theme.Master位于同一文件夹中,则不能找到css。

Have I made sense?

我有道理吗?

Very Frustrated

4 个解决方案

#1


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!

编辑因为您评论说这不起作用,我查找了我找到解决方案的地方。我在这篇博文中从Lance Fisher那里得到了它。如果没有清除它(因为它是在讨论java脚本文件),你也可以在这里查看之前回答的类似问题。希望有所帮助!

#2


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.

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

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:

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

<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:

对于记录,由于web.config文件中的这些指令,它在Views文件夹中不起作用(注意,Views文件夹中直接有一个web.config文件)。这只是仅供参考。我并不建议你试着弄乱这些,因为他们在那里有一般的理由:

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

#3


Have you tried using a rooted path? Such as:

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

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

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

#4


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, ~/

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

Fundamentally, this is similar to the same problem (with scripts) discussed here.

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

#1


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!

编辑因为您评论说这不起作用,我查找了我找到解决方案的地方。我在这篇博文中从Lance Fisher那里得到了它。如果没有清除它(因为它是在讨论java脚本文件),你也可以在这里查看之前回答的类似问题。希望有所帮助!

#2


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.

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

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:

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

<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:

对于记录,由于web.config文件中的这些指令,它在Views文件夹中不起作用(注意,Views文件夹中直接有一个web.config文件)。这只是仅供参考。我并不建议你试着弄乱这些,因为他们在那里有一般的理由:

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

#3


Have you tried using a rooted path? Such as:

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

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

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

#4


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, ~/

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

Fundamentally, this is similar to the same problem (with scripts) discussed here.

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