2

如何使 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" /> 但我想这更像是一种解决方法,而不是真正的解决方案。

4

1 回答 1

0

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

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");
}
于 2012-11-24T21:24:28.183 回答