【问题标题】:Static content in ASP.NET MVC in IIS 7IIS 7 中 ASP.NET MVC 中的静态内容
【发布时间】:2010-12-28 20:49:43
【问题描述】:

我在 II7 和 Windows 2008 Server 上运行 ASP.NET MVC 1.0 应用程序 (.NET 3.5)。 该应用程序以“集成管道”模式部署。

在 Global.asax.cs 我添加了:

public void Application_EndRequest(Object sender, EventArgs e) {
//print URL
}

即使是 /Content 和 /Scripts 文件夹中的静态内容(图像、css、js)也会调用该方法。 这是正确的吗?

MSDN (http://msdn.microsoft.com/en-us/library/bb470252.aspx) 说:

"The Execute handler stage, where the handler (a module scoped to a URL) is invoked to construct the response. For .aspx files, the PageHandlerFactory handler is used to respond to the request. 
For static files, the native-code StaticFileModule module responds to the request. "

那么应该为静态内容调用 Application_EndRequest() 吗?

如何确保浏览器缓存静态内容?

谢谢。

【问题讨论】:

    标签: asp.net-mvc iis-7


    【解决方案1】:

    由于 MVC 中引入的路由功能,现在一切都通过 ASP.NET 处理,因此每个请求都会调用 Application_EndRequest。浏览器无法看到静态或动态内容之间的区别,并且会尽可能根据 HTTP 标头尝试缓存内容。

    【讨论】:

      【解决方案2】:

      虽然 ASP MVC 默认模板不鼓励这样做,但我认为将网站的所有静态内容放在一个目录中将成为一种推荐做法。然后,您可以禁用该目录的 ASP 管道,并允许 IIS 提供内容,而无需将请求传递给 ASP.NET。

      这种做法已在 Steve SandersonKazi Manzur Rashid's 博客上进行了介绍。在ASP.NET MVC in Action也推荐。

      【讨论】:

      • 谢谢。但 Steve Sanderson 的博客是关于 IIS6 的。
      猜你喜欢
      • 1970-01-01
      • 2017-11-08
      • 2012-01-13
      • 1970-01-01
      • 2012-12-22
      • 2011-06-24
      • 2013-06-22
      • 2012-11-20
      • 2016-07-19
      相关资源
      最近更新 更多