我正在开发一个基于 ASP.NET MVC 的测试应用程序。 我对 CSS 很陌生,所以我也在学习它。
我创建了一个名为“new.master”的母版页,并创建了一个新的 css“new.css”。 我从控制器调用视图为:
return View ("About", "new");
我正在做的是经常更新 css 和母版页。 所以我经常在调试模式下运行应用程序。 一段时间后,我不再看到 css 更改的效果。 当我在 chrome 中“查看源代码”并检查 css 时,它显示旧版本。
当我更改母版页和 CSS 的名称时,我开始收到更新的视图,但这会持续一段时间,然后我再次停止获取 CSS 更新。 你遇到过这个问题吗? 我该如何修复它? (真是太烦人了!)
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.
I have created a master page called "new.master" and created a new css "new.css". I am calling the view from controller as:
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.
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!)
发布评论
评论(9)
您的浏览器正在缓存 CSS。 如果使用 F5 强制刷新,应该会显示任何更改。
Your browser is caching the css. If you force a refresh with F5 that should display any changes.
我认为这可能是浏览器缓存问题。 在 IE 和 FF 中,我通常使用 Ctrl + F5 或 Ctrl + 刷新按钮。 您也可以手动清除缓存。 对于 IE,您可以使用 IE开发工具栏,对于 Firefox,有 Firebug,两者都可以轻松清除缓存。 不太清楚 chrome 的情况,抱歉。
Sayed Ibrahim Hashimi
我的书:Microsoft 构建引擎内部:使用 MSBuild 和 Team Foundation Build
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 Toolbar and for Firefox there is Firebug with both you can clear the cache easily. Not sure about chrome, sorry.
Sayed Ibrahim Hashimi
My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build
右键单击“检查”进入 chroom 开发人员面板 -> 然后转到网络点击 -> 勾选“禁用缓存”复选框(注意:应始终选中该复选框)-> 按 F5 刷新页面。
这对我有用,希望这可以帮助有此问题的其他人! :)
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.
this work for me, hope this help others who have this issue! :)
我发现了另一个可能发生这种情况的情况。
我们仅使用 CSS 文件的简单链接启动应用程序,然后改用捆绑。 我们将旧的
更新为 <代码>@Styles.Render(“~/Styles/bundles/someStyle”)。
我们还使用了一些仅某些页面需要的样式表,并且它们有自己的捆绑包。 现在,对于其中之一,我们忘记将链接标记更改为 @Styles.Render 语句。
结果是这个 CSS 时不时地更新(所以我们认为一切正常;样式没有丢失),但我们无法影响更新何时发生。 当我开始更改文件时,我意识到我所做的任何事情(清空缓存、重建项目、重新启动 Cassini)都不会触发更新。 浏览器总是收到
304 Not Modified
。因此,如果您有这些症状,请检查您的链接。
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")
.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.
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
.So, if you have these symptoms, check your links.
请使用 Ctrl+F5 刷新浏览器。
即使内容发生更改,F5 也可能会为您提供相同的页面,因为它可能会从缓存加载页面。 但是 Ctrl - F5 会强制刷新缓存,并且将保证如果内容发生更改,您将获得新的内容。
希望这对你有帮助
谢谢
Please use Ctrl+F5 to refresh your browser.
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.
hope this will help you
Thank you
CSS 很可能被缓存在您的浏览器中,因此只需清除浏览器缓存,它应该会有所帮助
It's very possible that css is being cached in your browser, so simply clearch browser cache, it should help
当我有一个主视图时,这发生在我身上,该视图会根据用户想要查看的部分视图加载部分视图,但此页面的答案有帮助,https://forums.asp.net/t/1763494.aspx?applying+CSS+layouts+to+ a+部分+视图
我的部分视图中会有 css 链接,即使我在浏览器中按 Ctrl-F5,对 css 文件的任何修改也永远不会发生。 我还尝试在开发者工具中清除缓存内容。 通过查看源样式表,我注意到由部分视图链接的 css 文件没有更改,因此我的修复方法是将 css 链接从部分视图移动到保存这些部分视图的主视图。
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
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.
我身上也发生过类似的事情。
然后突然注意到捆绑包被添加到页面中:
而不是:
注意第一个示例中缺少的
~
字符。(第一个示例仅在构建项目后才有效,否则即使在调试模式下也会返回缓存版本。)
I had something similar happening to me.
Then suddenly noticed the bundle was added to the page:
instead of:
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.)
这可以帮助解决开发和生产中的这个问题。
使用 asp-append-version="true"
This can help solve this issues in both dev and production.
use asp-append-version="true"