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.

  • 相关阅读:
    pip换国内源
    docker build 的 cache 机制
    jenkins 修改log路径
    lsb_release: command not found 解决
    Linux 添加开机启动项的三种方法
    FAT AP v200R005 配置二层透明模式(web&命令行,开局)
    SharePoint 2010 文档管理系列之星级评论功能
    SharePoint 2010 文档管理之过期归档工具
    SharePoint 2010 文档管理系列之文档搜索
    SharePoint 2010 文档管理系列之准备篇
  • 原文地址:https://www.cnblogs.com/baozhu/p/3869725.html
Copyright © 2011-2022 走看看