Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent ASP.NET MVC from handling Static files (js and images) on Windows Azure?

I have an ASP.NET MVC application that is hosted on Windows Azure and all the static files served from the website are being processed by ASP.NET. Is there a way to get IIS to serve the static files directly and not route those requests through ASP.NET? I'm looking to help improve the performance of returning those static files from the server.

I'm not sure if this is something that ASP.NET MVC itself does, or if it's because of the fact that I'm hosting it on Azure.

UPDATE: The main reason I'm looking to do this is because the static files are processed by all HttpModules registered in the application, thus slowing performance some.

like image 935
Chris Pietschmann Avatar asked Sep 06 '11 14:09

Chris Pietschmann


People also ask

Which of the following middleware must be installed to serve static files in ASP.NET Core application?

To serve static files from an ASP.NET Core app, you must configure static files middleware. With static files middleware configured, an ASP.NET Core app will serve all files located in a certain folder (typically /wwwroot).

Where do we store static content in an MVC application?

Static files are stored within the project's web root directory. The default directory is {content root}/wwwroot , but it can be changed with the UseWebRoot method. For more information, see Content root and Web root. The preceding code was created with the web app template.

Which of the following static files can ASP.NET Core application serve?

ASP.NET Core can serve static files—HTML files, images, JavaScript files, etc. —directly to clients. To enable ASP.NET Core to serve static files, you must use the framework's Static Files Middleware in your application, and you must specify the necessary configuration.

What are static files in ASP.NET Core API project?

ASP.NET MVC 5 for Beginners Static files like JavaScript files, images, CSS files that we have on the file system are the assets that ASP.NET Core application can serve directly to clients. Static files are typically located in the web root (wwwroot) folder.


1 Answers

I removed the "runAllManagedModulesForAllRequests='true'" definition in the web.config and added "preCondition='managedHandler" to the HttpModule registrations that I don't want to execute for static content.

I also implemented Darin's answer.

Not entirely what I was looking for, but it seems to fit the bill.

UPDATE: if you remove "runAllManagedModulesForAllRequests=true" from web.config, make sure your IIS is up to date, otherwise extensionless URIs won't work anymore. KB about that: http://support.microsoft.com/kb/980368/en-us

(Of course, even if you keep that option, your should worry about your server being up to date.)

like image 185
Chris Pietschmann Avatar answered Sep 29 '22 04:09

Chris Pietschmann