繁体   English   中英

在ASP .NET中将图像写入响应中将导致“使用自定义TextWriter时,OutputStream不可用。”

[英]Writing image to response in ASP .NET results in “OutputStream is not available when a custom TextWriter is used.”

我们多年来一直在运行ASP.NET(无MVC)应用程序,没有任何问题。 但是,我们现在已经更改了服务器,现在出现以下错误:

使用自定义TextWriter时,OutputStream不可用。

异常详细信息:System.Web.HttpException:使用自定义TextWriter时,OutputStream不可用。

堆栈跟踪:

[HttpException(0x80004005):使用自定义TextWriter时,OutputStream不可用。] System.Web.HttpResponse.BinaryWrite(Byte []缓冲区)+4840090 App.Loader.Page_Load(对象发送器,EventArgs e)+3464

请参阅下面的代码:

public partial class Loader : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {   
        var filePath = @"C:\test\testfile.jpg";

        Response.Clear();
        Response.ContentType = "image/jpeg";
        Response.BinaryWrite(File.ReadAllBytes(filePath));
        Response.End();
    }
}

我已经注意到,一旦访问了Response对象的OutputStream属性,就会发生该错误。 我在这里和网络上都发现了很多类似的问题,但恐怕这些问题总是存在于mvc应用程序的上下文中。

提前非常感谢您!

我现在找到了解决方案。 我正在与此应用程序一起运行cms系统umbraco,它的新版本使用MVC框架作为基础框架。 因此,我认为Response对象在某种程度上不再有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM