4
votes

I have ASP.NET MVC 1.0 application (.NET 3.5) running on II7 and Windows 2008 Server. The application is deployed in 'Integrated Pipeline' mode.

In Global.asax.cs I added:

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

The method is being called even for static content (images,css,js) in /Content and /Scripts folders. Is this correct ?

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

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

So should Application_EndRequest() be called for static content ?

How to ensure browser is caching static content ?

Thank You.

2

2 Answers

1
votes

Because of the routing functionality introduced in MVC everything is now handled through ASP.NET and so Application_EndRequest will be called for every request. A browser can not see the difference between static or dynamic content and will try to cache content if possible and depending on the HTTP headers.

1
votes

Although it isn't encouraged by the ASP MVC default template, I think that it will become a recommended practice to place all of your site's static content within a single directory. You can then disable the ASP pipeline for said directory and allow IIS to serve the content without passing the request to ASP.NET at all.

This practice has been written about on Steve Sanderson and Kazi Manzur Rashid's blogs. It is also recommended in ASP.NET MVC in Action.