【问题标题】:Writing image to response in ASP .NET results in "OutputStream is not available when a custom TextWriter is used."在 ASP .NET 中将图像写入响应会导致“使用自定义 TextWriter 时,OutputStream 不可用”。
【发布时间】:2015-02-02 11:32:52
【问题描述】:

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

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

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

堆栈跟踪:

[HttpException (0x80004005): 使用自定义 TextWriter 时,OutputStream 不可用。] System.Web.HttpResponse.BinaryWrite(Byte[] 缓冲区) +4840090 App.Loader.Page_Load(Object sender, 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 应用程序的上下文中。

非常感谢您!

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    我现在找到了解决方案。 我正在使用这个应用程序运行 cms 系统 umbraco,它的新版本使用 MVC 框架作为底层框架。因此,我认为 Response 对象不再有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-18
      • 1970-01-01
      • 1970-01-01
      • 2013-03-15
      相关资源
      最近更新 更多