难道文件()在asp.net mvc的关闭流? [英] Does File() In asp.net mvc close the stream?

查看:69
本文介绍了难道文件()在asp.net mvc的关闭流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如果你做这样的事情。

 公共FileResult结果()
{
   流流=新流();
   返回文件(流t​​ext / html的,bob.html);
}

如果文件()将关闭为你流?因为我试图把流,在using语句,但它总是给我一个错误说在流关闭。

 公共FileResult结果()
{
    使用(流流=新流())
    {
       返回文件(流t​​ext / html的,bob.html);
    }
}


解决方案

如果您使用的是文件对象发送生成的文件以供下载bob.html然后是

我相信,关闭或处置时,将所有的标准流(OutputStream的,的FileStream,CryptoStream的)将尝试刷新。

有许多的MVC框架实现基地内的类 FileResult 类。

  System.Web.Mvc.FileResult
System.Web.Mvc.FileContentResult
System.Web.Mvc.FilePathResult
System.Web.Mvc.FileStreamResult

I am wondering if you do something like

public FileResult result()
{
   Stream stream = new Stream();
   return File(stream,"text/html","bob.html");
}

if File() would close the stream for you? Since I tried to put the "stream" in a using statement but it always gave me a error saying the stream was closed.

public FileResult result()
{
    using(Stream stream = new Stream())
    {
       return File(stream,"text/html","bob.html");
    }
}

解决方案

If you are using the File object to send the resulting file for download as bob.html then yes.

I believe that all standard Streams (OutputStream, FileStream, CryptoStream) will attempt to flush when closed or disposed.

There are a number of classes within the MVC framework that implement the base FileResult class.

System.Web.Mvc.FileResult
System.Web.Mvc.FileContentResult
System.Web.Mvc.FilePathResult
System.Web.Mvc.FileStreamResult

这篇关于难道文件()在asp.net mvc的关闭流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆