调试 ASP.NET MVC 应用程序期间未更新 CSS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1137775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:49:38  来源:igfitidea点击:

CSS not updated during debugging ASP.NET MVC application

asp.net-mvccssmaster-pages

提问by Hemant

I am working on a test application based on ASP.NET MVC. I am new to CSS stuff so I am learning that as well.

我正在开发基于 ASP.NET MVC 的测试应用程序。我是 CSS 的新手,所以我也在学习。

I have created a master page called "new.master" and created a new css "new.css". I am calling the view from controller as:

我创建了一个名为“new.master”的母版页,并创建了一个新的 css“new.css”。我从控制器调用视图为:

return View ("About", "new");

What I am doing is that I am frequently updating the css and master page. So I run the application in debug mode frequently. After sometime I stop seeing the effect of changes in css. When I "view source" in chrome and check the css, it shows an old version.

我正在做的是我经常更新 css 和母版页。所以我经常在调试模式下运行应用程序。一段时间后,我不再看到 css 更改的效果。当我在 chrome 中“查看源代码”并检查 css 时,它显示的是旧版本。

When I change the name of both master page and css, I start to receive updated views but that works for sometime and then again I stop getting the CSS updates. Have you faced this problem? How can I fix it? (Its terribly annoying!)

当我更改母版页和 css 的名称时,我开始接收更新的视图,但这会起作用一段时间,然后我再次停止获取 CSS 更新。你遇到过这个问题吗?我该如何解决?(实在是太烦人了!)

回答by blu

Your browser is caching the css. If you force a refresh with F5 that should display any changes.

您的浏览器正在缓存 css。如果您使用 F5 强制刷新,则应显示任何更改。

回答by Sayed Ibrahim Hashimi

I think this may be a browser cache issue. In in IE and FF I usually do Ctrl + F5 or Ctrl + Refresh button. Also you can manually clear the cache. For IE you can use the IE Dev Toolbarand for Firefox there is Firebugwith both you can clear the cache easily. Not sure about chrome, sorry.

我认为这可能是浏览器缓存问题。在 IE 和 FF 中,我通常使用 Ctrl + F5 或 Ctrl + Refresh 按钮。您也可以手动清除缓存。对于 IE,您可以使用IE 开发工具栏,对于 Firefox,您可以使用Firebug轻松清除缓存。不确定铬,抱歉。

Sayed Ibrahim Hashimi

赛义德·易卜拉欣·哈希米

My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build

我的书:Microsoft Build Engine 内部:使用 MSBuild 和 Team Foundation Build

回答by Rumi P.

I found another case in which this can happen.

我发现了另一个可能发生这种情况的情况。

We started our application with just plain links to the CSS files, then switched to using bundling. We updated the old <link href="@Url.Content("~/somePath/someStyle.css")" rel="stylesheet" type="text/css" />to @Styles.Render("~/Styles/bundles/someStyle").

我们以简单的 CSS 文件链接开始我们的应用程序,然后切换到使用捆绑。我们将旧版本更新<link href="@Url.Content("~/somePath/someStyle.css")" rel="stylesheet" type="text/css" />@Styles.Render("~/Styles/bundles/someStyle").

We also use a few stylesheets which are only needed for some pages, and they have their own bundle. Now, for one of them, we forgot to change the link tag to the @Styles.Render statement.

我们还使用了一些仅在某些页面上需要的样式表,并且它们有自己的包。现在,对于其中之一,我们忘记将链接标记更改为 @Styles.Render 语句。

The result was that this CSS got updated now and then (so we thought everything is OK; the style wasn't missing), but we could not influence when the update happens. When I started making changes to the file, I realized that nothing I do (emptying the cache, rebuilding the project, restarting Cassini) will trigger an update. The browser always got a 304 Not modified.

结果是这个 CSS 不时更新(所以我们认为一切正常;样式没有丢失),但我们无法影响更新发生的时间。当我开始对文件进行更改时,我意识到我所做的任何事情(清空缓存、重建项目、重新启动 Cassini)都会触发更新。浏览器总是有一个304 Not modified.

So, if you have these symptoms, check your links.

因此,如果您有这些症状,请检查您的链接。

回答by Tadeusz Wójcik

It's very possible that css is being cached in your browser, so simply clearch browser cache, it should help

css 很有可能被缓存在你的浏览器中,所以只需清除浏览器缓存,它应该会有所帮助

回答by Mousa Al-Kalouti

go to chroom developer panel by right click inspect -> then go to Network tap -> tick the Disable cache checkbox (note: this should always be checked) -> Refresh the page by pressing F5.

通过右键单击检查转到 chroom 开发人员面板 -> 然后转到网络点击 -> 勾选禁用缓存复选框(注意:应始终选中)-> 按 F5 刷新页面。

this work for me, hope this help others who have this issue! :)

这对我有用,希望这可以帮助遇到此问题的其他人!:)

回答by Chris Gong

This happened to me when I had a master view that would load partial views depending on which partial view the user wanted to see, but the answer from this page helped, https://forums.asp.net/t/1763494.aspx?applying+CSS+layouts+to+a+partial+view

当我有一个主视图时,这发生在我身上,该视图会根据用户想要查看的部分视图加载部分视图,但此页面的答案有帮助,https://forums.asp.net/t/1763494.aspx?应用+CSS+布局+to+a+部分+视图

CSS must be referenced in the of the Html document. As a consequence you cannot include them in a partial view...because in such case the css is included in the Html body. Please plce the style sheet in head of the page that hosts the partial view.

必须在 Html 文档的 中引用 CSS。因此,您不能将它们包含在部分视图中……因为在这种情况下,css 包含在 Html 正文中。请将样式表放在承载部分视图的页面的头部。

I would have css links in my partial views and any modifications to the css files would never happen, even if I pressed Ctrl-F5 in the browser. I also tried clearing cache contents in the developer tools. I noticed by viewing the source stylesheets that the css files linked by the partial views were not changing, so the fix for me was to move the css links from the partial view to the main view where these partial views were to be held.

我的部分视图中会有 css 链接,并且对 css 文件的任何修改都不会发生,即使我在浏览器中按下了 Ctrl-F5。我还尝试清除开发人员工具中的缓存内容。我通过查看源样式表注意到由部分视图链接的 css 文件没有改变,所以我的解决方法是将 css 链接从部分视图移动到要保存这些部分视图的主视图。

回答by Dilip Kumar Choudhary

Please use Ctrl+F5 to refresh your browser.

请使用 Ctrl+F5 刷新您的浏览器。

F5 may give you the same page even if the content is changed, because it may load the page from cache. But Ctrl - F5 forces a cache refresh, and will guarantee that if the content is changed, you will get the new content.

即使内容更改,F5 也可能为您提供相同的页面,因为它可能会从缓存中加载页面。但是 Ctrl - F5 强制刷新缓存,并保证如果内容发生更改,您将获得新内容。

hope this will help you

希望能帮到你

Thank you

谢谢

回答by BlueTabasco

I had something similar happening to me.

类似的事情发生在我身上。

Then suddenly noticed the bundle was added to the page:

然后突然注意到这个bundle被添加到了页面中:

@Styles.Render("/bundles/classifiedDetailCss")

instead of:

代替:

@Styles.Render("~/bundles/classifiedDetailCss")

Note the missing ~character in the first example.

请注意~第一个示例中缺少的字符。

(The first example only worked after building the project, otherwise it would return a cached version even in debug mode.)

(第一个示例仅在构建项目后才有效,否则即使在调试模式下它也会返回缓存版本。)