Cassini 上的 ASP.NET MVC:如何强制“内容”目录返回 304s 而不是 200s?

发布于 2024-09-14 01:53:26 字数 616 浏览 2 评论 0原文

场景:我有一个在 Visual Studio 2008 中开发的 ASP.NET MVC 应用程序。有一个名为“Content”的根文件夹,用于存储图像和样式表。当我在本地运行(使用 Cassini)并浏览我的应用程序时,“Content”目录中的每个资源总是被下载。使用 Firebug,我可以验证 Web 服务器是否返回 HTTP 200(“ok”)。

期望:我希望 Cassini 返回 HTTP 304(“未修改”)而不是 200。这是在 IIS7 下运行站点时的行为。

推理:我正在工作的网站有大量静态资源(通常每页多达 40 个)。在 IIS7 上浏览站点速度非常快,因为这些资源被浏览器(正确地)缓存了。然而,在我的本地计算机上浏览该网站的速度非常慢。

在 IIS7 上渲染时间不到 1 秒的页面在 Cassini 上渲染需要 30 秒以上。对于我来说,每隔几分钟上传整个网站并从那里进行测试实际上更快。 (是的,我认识到这是反常和疯狂的。)

那么:如何指示/欺骗 Cassini 像 IIS7 一样对待“Content”目录

Scenario: I have an ASP.NET MVC application developed in Visual Studio 2008. There is a root folder named "Content" that stores images and stylesheets. When I run locally (using Cassini) and browse my application, every resource from the "Content" directory is always downloaded. Using Firebug, I can verify that the web server returns an HTTP 200 ("ok").

Desired: I would like for Cassini to return HTTP 304 ("not modified") instead of 200. This is the behavior when running the site under IIS7.

Reasoning: The site I am working on has a large number of static resources (often as many as 40 per page). Browsing the site is very fast on IIS7, because these resources are (correctly) cached by the browser. However, browsing the site on my local machine is painfully slow.

Pages that render in under 1 second on IIS7 take over 30 seconds to render on Cassini. It's actually faster for me to upload the entire website every few minutes and test from there. (Yes, I recognize that this is perverse and crazy.)

So: how can I instruct/trick Cassini into treating the "Content" directory like IIS7 does?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

还不是爱你 2024-09-21 01:53:26

您确定问题出在缓存上吗?因为当我在 Cassini 上运行应用程序时,内容确实会正确缓存在我的计算机上。

我认为您遇到的问题可能是 Firefox 在解析 IPv6 地址时性能不佳,这会导致加载 http 等地址时出现非常烦人的延迟//本地主机:55555

为了改变这种行为,我所做的就是在 Firefox 上将 about:config 上的 network.dns.disableIPv6 首选项更改为 true。我建议尝试一下。

Are you sure the problem is caching? Because the content does get cached correctly on my machine when I run the application on Cassini.

I think the problem you're having could be Firefox's under-performance with resolving IPv6 addresses, which causes a very annoying delay on loads with addresses like http://localhost:55555.

What I did to change this behaviour was to change the network.dns.disableIPv6 preference on about:config to true on Firefox. I suggest trying that.

如梦 2024-09-21 01:53:26

我在 Chrome 中也遇到过类似的问题。要解决此问题,请取消 hosts 文件中 IPv4 localhost 行的注释。显然这些在 Windows 7 中是默认注释的。

127.0.0.1       localhost
#::1             localhost

I've had a similar problem in Chrome. To resolve this uncomment the IPv4 localhost line in you hosts file. Apparently these are commented by default in Windows 7.

127.0.0.1       localhost
#::1             localhost
著墨染雨君画夕 2024-09-21 01:53:26

您的另一个选择是简单地跳过 Cassini 和 IIS 下调试。它非常简单,不会花费您十分钟即可启动并运行。在 Cassini 上浏览 20 个页面,无论如何,您已经使用了这段时间;)

我注意到的一件事并不总是在指南中,那就是如果您想在与 http:// 不同的地址上进行调试/localhost/ 您需要手动将主机设置为您本地的IIS。这是通过在 hosts 文件中添加一行来完成的,该文件位于

C:\Windows\system32\drivers\etc\hosts

使用记事本打开该文件(您需要“以管理员身份运行”才能如果您使用的是 Windows Vista 并打开了用户帐户控制,则可以保存...)并添加您的主机。例如,要在 http://mysite/ 下调试,您添加

mysite         127.0.0.1

Another option for you is to simply skip Cassini and debug under IIS. It's pretty straightforward, and won't take you ten minutes to get up and running. Browse 20 of your pages on Cassini, and you've used that time anyway ;)

One thing I've noticed isn't always in the guides, is that if you want to debug on a different address than http://localhost/ you need to manually set the host to your local IIS. This is done by adding a line in the hosts file, located at

C:\Windows\system32\drivers\etc\hosts

Open the file with notepad (you need to "Run as Administrator" in order to be able to save if you're using Windows Vista and have User Account Control turned on...) and add your host. For example, to debug under http://mysite/ you add

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