WHEN STATICFILEHANDLER IS NOT STATICFILEHANDLER

I could also have called this "wildcard .NET mapping in IIS Express from web.config."

I‘m sure that, like, everyone out there but me has figured this out by now, but... well, I‘ll blog it anyway.

Problem: Your ASP.NET web site has a VirtualPathProvider that serves static files (e.g., .jpg, .css, etc.). It works great in the Visual Studio development web server but switching to IIS Express, it suddenly doesn‘t work.

My team has just such a provider that serves static files out of embedded resources. We switched from Cassini over to IIS Express and couldn‘t for the life of us figure out why it suddenly stopped working. I mean, it‘s "integrated pipeline," right? WTF?

OK, so my first "duh!" moment was when I realized that it‘s integrated pipeline, not ".NET is responsible for handling each request." That is, you have a managed request pipeline but the actual handler that serves the content may or may not be managed. It‘s one of those things you know, then forget you know, then remember again when you hit a snag.

At that point I went looking in config to see what the handler was for static files and I saw this in the system.webServer/handlers section of applicationhost.config:

<add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />

This is where I made my mistake. I know what the line there says, but in my mind, I read it as "Use the StaticFileHandler for any files not previously mentioned." So I‘m thinking System.Web.StaticFileHandler, right? It‘s integrated, so that‘s your built-in wildcard mapping... right?

That‘s not what it says.

It says, "When all else fails, use the unmanaged default mechanism to serve up the static content." Which, further, means "skip all VirtualPathProviders and go right to disk."

My teammate, Sagar, figured that one out and we were both slapping our foreheads. Of course. Again, integrated pipeline, not ".NET handles all requests."

The fix is to add the .NET static file handler back into your pipeline. You can do this in your web.config in system.webServer/handlers:

<add name="AspNetStaticFileHandler" path="*" verb="*" type="System.Web.StaticFileHandler" />

We did that, and suddenly things were working again. Bam! Done.

Note that doing this has some performance and caching implications. The unmanaged, standard IIS static file handler is pretty well optimized for performance; more so than the managed static file handler. Also, the managed static file handler doesn‘t write caching-related information (e.g., ETag or Expires headers) for virtual files that are not served up from disk. Something to consider.

WHEN STATICFILEHANDLER IS NOT STATICFILEHANDLER

时间: 2024-10-12 14:47:27

WHEN STATICFILEHANDLER IS NOT STATICFILEHANDLER的相关文章

tornado.web.StaticFileHandler

tornado.web.StaticFileHandler 源代码中的解释 class StaticFileHandler(RequestHandler): """A simple handler that can serve static content from a directory. A `StaticFileHandler` is configured automatically if you pass the ``static_path`` keyword arg

tarnado源码解析系列一

目录 tarnado tarnado源码安装 tarnado测试程序 application类的解析 一. tarnado简介 最近在学习Python,无意间接触到的tarnado,感觉tarnado还蛮好的那么tarnado到底什么呢?tarnado是由Python开发的一个非阻塞式web服务器框架,他与许多主流的web框架有很大的不同(当然其他的web框架我还真的不知道多少),epoll和非阻塞的方式让他可以每秒数以千计的连接,非常适合与实时的web服务.以下地址为tarnado官方的解释h

Python框架之Tornado(二)请求阶段

概述 上图是tornado程序启动以及接收到客户端请求后的整个过程,对于整个过程可以分为两大部分: 启动程序阶段,又称为待请求阶段(上图1.2所有系列和3.0) 接收并处理客户端请求阶段(上图3系列) 简而言之: 1.在启动程序阶段,第一步,获取配置文件然后生成url映射(即:一个url对应一个XXRequestHandler,从而让XXRequestHandler来处理指定url发送的请求):第二步,创建服务器socket对象并添加到epoll中:第三步,创建无线循环去监听epoll. 2.在

asp.net web.config 网载文章重新复习一下

在开发中经常会遇到这样的情况,在部署程序时为了保密起见并不将源代码随项目一同发布,而我们开发时的环境与部署环境可能不一致(比如数据库不一样),如果在代码中保存这些配置这些信息部署时需要到用户那里更改代码再重新编译,这种部署方式非常麻烦.在.net中提供了一种便捷的保存项目配置信息的办法,那就是利用配置文件,配置文件的文件后缀一般是.config,在asp.net中配置文件名一般默认是web.config.每个web.config文件都是基于XML的文本文件,并且可以保存到Web应用程序中的任何目

asp.net web.config配置节说明

web.config 文件查找规则:      (1)如果在当前页面所在目录下存在web.config文件,查看是否存在所要查找的结点名称,如果存在返回结果并停止查找.      (2)如果当前页面所在目录下不存在web.config文件或者web.config文件中不存在该结点名,则查找它的上级目录,直到网站的根目录.      (3)如果网站根目录下不存在web.config文件或者web.config文件中不存在该节点名则在%windir%"Microsoft.NET"Frame

tornado源码分析系列一

先来看一个简单的示例: #!/usr/bin/env  python #coding:utf8 import socket def run():     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)     sock.bind(('127.0.0.1',8008))     sock.listen(5)          while True:         connection,address = sock.accept()

配置文件入门 - WebConfig.config常用配置节点介绍

一.配置文件入门 .Net提供了一种保存项目配置信息的办法,就是利用配置文件,配置文件的后缀一般是.config.在WinForm程序中配置文件一般是App.config.在Asp.net中一般默认是web.config. 一个.config配置文件都是基于XML的文本文件,并且可以保存到Web应用程序中的任何目录中.在发布Web应用程序时web.config文件并不编译进dll文件中.将来如果客户端发生了变化,仅仅需要使用记事本打开Web.config文本编辑相关的设置就可以重新正常使用,而无

我的设计模式总结

各位小牛大牛老鸟菜鸟们好,欢迎参观我的设计模式世界.这个世界我已经总结多年了,现在才刚刚成型.But I have a dream,梦想所有开发者都能一夜之间认清所有设计模式,还幻想以后大家认识设计模式时,必首先google本文,嘿嘿. 前辈同仁们已经总结过很多,至今首页上设计模式的文章仍然层出不穷.但我总认为,在GOF的23个设计模式提出多年了,该需要些变化和扩展了.特别适用于.NET(或Mono)的设计模式,好像没有系统的总结.新年伊始,推出这篇总结,我个人不喜欢人云亦云,对设计模式的整体,

asp.net中web.config配置节点大全详解【转】

web.config 文件查找规则: (1)如果在当前页面所在目录下存在web.config文件,查看是否存在所要查找的结点名称,如果存在返回结果并停止查找. (2)如果当前页面所在目录下不存在web.config文件或者web.config文件中不存在该结点名,则查找它的上级目录,直到网站的根目录. (3)如果网站根目录下不存在web.config文件或者web.config文件中不存在该节点名则在%windir%"Microsoft.NET"Framework"v2.0.