【问题标题】:Image HttpMessageResponse responding but not displaying?图像 Http 消息响应响应但不显示?
【发布时间】:2014-04-24 01:32:50
【问题描述】:

我目前正在更新一个旧站点以使用 Hot Towel 框架,当前站点所做的一件事是使用 HTTPMessageResponse 加载图像。这在旧设置中可以正常工作,但是在新设置中,图像不会显示并且转到 URL 会产生...

StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.ByteArrayContent, Headers: { Content-Type: image/png }

我查看了两个应用程序产生的响应,并且来自以下函数的响应匹配(响应与上面相同,内容完全匹配)...

namespace OPC.Controllers
{
    public class ImageController : Controller
    {
        public HttpResponseMessage GetImage(int imageId)
        {
            var blob = new byte[10];
            var context = new OPCEntity();
            var ImageString = context.sp_GetImageData(imageId);
            foreach (var Result in ImageString)
            {
                blob = Result.Data;
            }
            Image image;
            var ms = new MemoryStream();
            ms.Write(blob, 0, blob.Length);
            var result = new HttpResponseMessage(HttpStatusCode.OK);
            result.Content = new ByteArrayContent(ms.ToArray());
            result.Content.Headers.ContentType = new  System.Net.Http.Headers.MediaTypeHeaderValue("image/png");
            return result;
        }
    }
}

图片是在JS中使用...设置的

image.setAttribute('src', document.location.href.match(/(^[^#]*)/)[0] + '/Image/GetImage?imageId=' + imageDetails.imageId);

是否有人对我可能遗漏的内容有任何想法,或者热毛巾框架中的任何内容是否会干扰。

非常感谢。

【问题讨论】:

    标签: asp.net-mvc-4 breeze httpresponse hottowel


    【解决方案1】:

    好吧,我错过了一些重要的事情......事实上它应该......

    public class ImageController : ApiController{}
    

    但是我也发现微风网络 API 配置确实与正常的网络 API 配置冲突,所以暂时我不得不将 BreezeWebApiConfig.cs 更改为以下

    public static class BreezeWebApiConfig {
    
        public static void RegisterBreezePreStart() {
          GlobalConfiguration.Configuration.Routes.MapHttpRoute(
              name: "BreezeApi",
              routeTemplate: "api/{controller}/{action}"
          );
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多