3
ActionFilterを使用してコントローラで動的に生成されたファイルを削除しようとしています。私は応答をフラッシュし、その後、私はIOException: The process cannot access the file ... because it is being used by another process
例外を取得ファイルを削除することはできませんので、コードのコメントで述べたようにasp.netコアのActionFilterで応答をフラッシュする方法は?
public class DeleteFileAttribute : ActionFilterAttribute {
public override void OnActionExecuted(ActionExecutedContext context) {
/* MVC 4 code which worked just fine
context.HttpContext.Response.Flush();
var filePathResult = context.Result as FilePathResult;
if(filePathResult!=null){
File.Delete(filePathResult.FileName);
}
End of MVC 4 code */
// I am not able to flush response as context.HttpContext.Response does not have a Flush method
var vb = (context.Controller as Controller).ViewBag;
string fileToDelete = vb.FileToDelete;
if(File.Exists(fileToDelete)) {
// ERROR: Process cannot access the file ... because it is being used by another process
File.Delete(fileToDelete);
}
}
}
。
アクションフィルタでファイルを削除するには、ユーザーがダウンロードを完了したらどうすればよいですか?