zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    Android_AsyncTask
    table隔行变色【转】
    添加对WCF的调用(内网状态下)。
    【转】IDEA 2017破解 license server激活
    C# LIst去重
    框架内事务的近期发现,以后再研究
    启动、停止、删除Windows服务
    软件项目总结中的经验总结
    iis最大连接数和队列长度
    在一个千万级的数据库查寻中,如何提高查询效率?
  • 原文地址:https://www.cnblogs.com/baozhu/p/3869725.html
Copyright © 2011-2022 走看看