如何使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" />
这是微不足道的
但我想这更像是一种解决方法,而不是一种真正的解决方案。
答案 0 :(得分: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");
}