我开发了一个简单的 ashx 服务,它可以从遥远的系统中获取图像并将它们呈现在 .net 应用程序中。在应该与生产环境相同的开发中一切正常,因此这似乎是一个配置错误。
实现图像的页面也会在日志窗口中返回此消息
资源解释为图像,但使用 MIME 类型 text/html 传输
生产中
开发中
此外,环境中的代码和 web.config 等类似内容是相同的。我什至复制了整个开发树并在开发服务器上运行它,结果完全相同。
我的实现看起来像这样
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers accessPolicy="Read, Write, Script, Execute">
<remove name="SPImage" />
<add name="SPImage" verb="GET" path="SPImage.ashx" type="Web.Business.Handlers.SPImage, Web" />
</handlers>
</system.webServer>
和处理程序
namespace Web.Business.Handlers
{
public class SPImage : IHttpHandler
{
public bool IsReusable { get { return true; } }
public void ProcessRequest(HttpContext context)
{
Guid imageGuid;
if (!Guid.TryParse(context.Request.QueryString["id"], out imageGuid))
// Get user
var user = aspnet_MembershipController.Read<aspnet_MembershipListModel>(context.User.Identity.Name);
// Get requested image
var image = GalleryListController.ReadImage<IGalleryPicture>(user.ID, imageGuid);
byte[] file = DownloadProcedureController.Download<byte[]>("gallerier", image.Webimage);
int width = 270;
int height = 180;
// Return image in scaled format
var stream = new MemoryStream();
var settings = new ResizeSettings(string.Format("width={0};height={1};format=jpg;quality={2};mode=crop", width, height, 100)) {};
// ...process the image
new ImageResizer.ImageJob(file, stream, settings).Build();
HttpResponse httpResponse = context.Response;
httpResponse.ContentType = "image/jpeg";
//httpResponse.CacheControl = "no-cache";
httpResponse.BufferOutput = false; //Stream the content to the client, no need to cache entire streams in memory...
httpResponse.BinaryWrite(stream.GetBuffer());
httpResponse.End();
}
}
}
有人认得这个吗?
谢谢