遠く離れたシステムから画像を取得し、.net アプリケーションでレンダリングする単純な ashx サービスを開発しました。本番環境と同一であるはずの開発環境ではすべてが正常に機能するため、これは構成エラーのようです。
画像が実装されているページでも、ログ ウィンドウにこのメッセージが返されます
リソースはイメージとして解釈されますが、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();
}
}
}
誰もこれを認識していますか?
ありがとう