返回FileStreamResult时,如果用using包裹FileStream,文件流被关闭,程序不能正常返回
public IActionResult GetModel(string modelName, string stage)
{
string modelPath = ModelModel.ReadModel(modelName);
using (FileStream fileStream = new FileStream(modelPath + stage + ".ini", FileMode.Open, FileAccess.Read))
{
return new FileStreamResult(fileStream, "application/json");
}
}
直接返回程序正常运行
public IActionResult GetModel(string modelName, string stage)
{
string modelPath = ModelModel.ReadModel(modelName);
return new FileStreamResult(new FileStream(modelPath + stage + ".ini", FileMode.Open, FileAccess.Read), "application/json");
}