【问题标题】:Serve static file if it exists else create it如果存在静态文件,则提供静态文件,否​​则创建它
【发布时间】:2012-11-24 13:31:01
【问题描述】:

如何让 StaticFile 处理程序只服务实际存在的文件,并让其他人转到 asp.net mvc 管道或自定义 http 处理程序。

1) GET /images/file.jpg
  exists => serve it (StaticFile handler / as efficiently as possible)

2) GET /images/file_640x480.jpg
  1. request (doesn't exist)
  * load file.jpg
  * resize
  * save as file_640x480.jpg
  => serve from memory

  following requests 
  => should use 1) because the file is now there

<modules runAllManagedModulesForAllRequests="true" /> 很简单 但我想这与其说是真正的解决方案,不如说是一种解决方法。

【问题讨论】:

    标签: asp.net asp.net-mvc iis httphandler


    【解决方案1】:

    我还没有尝试过这段代码,但是这些行中的某些东西应该可以工作

    public FilePathResult GetFile(string name)
    {
        FileInfo info = new FileInfo(name);
        if (!info.Exists)
        {
            //Code to load the original file, resize and save would go here
        }
    
        return File(name, "text/plain");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-29
      • 1970-01-01
      • 2014-07-25
      • 1970-01-01
      • 1970-01-01
      • 2013-03-29
      • 2011-06-30
      相关资源
      最近更新 更多