0

IIS 7.5 の ashx ファイルに関するヘルプが必要です。このアプリケーションは、VS 2005 Windows Server 2008 にあります。

ashx を使用して aspx ページで画像を開こうとしています。IIS 6.0 で Web サイトを作成したとき、画像が取得され、正常に表示されました。IIS 7.5 に移動した後、ashx ファイルが機能しなくなり、画像が表示されなくなりました。

www.website.com/imageout.ashx?height=63&width=42&categoryID=15&imageID=77

私はググって、IISでハンドラーを作成してweb.configをこのようなものに変更しようとしました。

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
        <remove name="SimpleHandlerFactory-Integrated" />
        <add name="SimpleHandlerFactory-Integrated" path="*.ashx" verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />           
    </handlers> 
</system.webServer>


<system.web>
    <httpHandlers>
        <remove verb="*" path="*.asmx" />
        <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />

    </httpHandlers>
.......
.....
 </system.web>

これは私のashxファイルがどのように見えるかです

<%@ WebHandler Language="C#" Class="imageout" %>

using System;
using System.Web;

public class imageout : IHttpHandler
{
public void ProcessRequest(HttpContext ctx)
{
    string strMerchantID = "";
    string strImageType = "";
    string strTemp = "";
    string strlocationID = "";
    string strcouponID = string.Empty;
    int categoryID = 0;
    string PageID = "";
    string DIImageID = "";
    int imageID = 0;
    string Marquee_ImageID = "";
    bool Ismarquee = false;
    bool isCategoryImage = false;
    bool IsPageID = false;
    long? couponID = 0;
    //*
    string TownID = "";
    //*
    int ImageID = 0;

    if (ctx.Request.QueryString["MerchantID"] != null)
    {
        strMerchantID = ctx.Request.QueryString["MerchantID"].ToString();
        strImageType = ctx.Request.QueryString["ImageType"].ToString();
        if (ctx.Request.QueryString["IsTemp"] != null)
            strTemp = ctx.Request.QueryString["IsTemp"].ToString();
        if (ctx.Request.QueryString["locationid"] != null)
            strlocationID = ctx.Request.QueryString["locationid"].ToString();
    }
    //*
    else if (ctx.Request.QueryString["TownID"] != null)
    {
        TownID = ctx.Request.QueryString["TownID"].ToString();
        strTemp = ctx.Request.QueryString["IsTemp"].ToString();
    }
    else if (ctx.Request.QueryString["RegionMarqueeID"] != null)
    {
        Marquee_ImageID = ctx.Request.QueryString["RegionMarqueeID"].ToString();
        Ismarquee = true;
    }
    //*
   // TownID = "151531";
    string tempStrImageType = strImageType;
    if (strImageType == "couponlogo")
        strImageType = "merchantlogo";

    if (ctx.Request.QueryString["couponid"] != null && ctx.Request.QueryString["couponid"] != "0")
    {
        strcouponID = ctx.Request.QueryString["couponid"].ToString();
        couponID = Sabre.Common.NullHandler.ConvertToLongNullable(strcouponID);
    }
    if (ctx.Request.QueryString["categoryID"] != null
        && ctx.Request.QueryString["categoryID"] != "F" 
        && ctx.Request.QueryString["imageID"] != null
        && ctx.Request.QueryString["imageID"] != "0")
    {
        categoryID = Sabre.Common.NullHandler.ConvertToInt(ctx.Request.QueryString["categoryID"].ToString());
        imageID = Sabre.Common.NullHandler.ConvertToInt(ctx.Request.QueryString["imageID"].ToString());
        isCategoryImage = true;
    }

    if (ctx.Request.QueryString["PageID"] != null && ctx.Request.QueryString["DIImageID"] != null)
    {
        PageID = ctx.Request.QueryString["PageID"].ToString();
        DIImageID = ctx.Request.QueryString["DIImageID"].ToString();
        IsPageID = true;
    }
    int width= 0;
    int height= 0;
    if (TownID != "")
    {
        if (TownID != "0")
        {
            if (strTemp == "0")
            {
                width = 720; height = 240;
            }
            else
            {
                width = 250; height = 194;
            }
        }
        else
        {
            width = 259; height = 352;
        }
    }
    else if (PageID != "")
    {
        width = 250; height = 150;
    }
    else if (Marquee_ImageID != "")
    {
        width = 475; height = 75;
    }
    else
    {
        width = 100; height = 50;
    }

    decimal hightImageRatio;
    decimal widthImageRatio;
    int OriginalWidth;
    int OriginalHeight;
    decimal imageRatio;
    byte[] imageData;

    try
    {
        if (ctx.Request.QueryString["width"] != null)
        {
            if (BusinessLogic.BLL.Common.IsInt(ctx.Request.QueryString["width"].ToString().Trim()))
                width = int.Parse(ctx.Request.QueryString["width"].ToString().Trim());
        }

        if (ctx.Request.QueryString["height"] != null)
        {
            if (BusinessLogic.BLL.Common.IsInt(ctx.Request.QueryString["height"].ToString().Trim()))
                height = int.Parse(ctx.Request.QueryString["height"].ToString().Trim());
        }

        ASPJPEGLib.ASPJpegClass objASPJpeg = new ASPJPEGLib.ASPJpegClass();
        if (categoryID != 0 && imageID != 0)
        {
            byte[] imageDataArray = new BusinessLogic.BLL.Admin().getPrimaryCategoryImages(categoryID, imageID);
            if (imageDataArray[0] != 0)
                objASPJpeg.OpenBinary(imageDataArray);
        }
        else
        {
            if (couponID != 0)
            {
                objASPJpeg.OpenBinary(new BusinessLogic.BLL.Coupon().GetBinaryBarcodeImage(couponID));
                width = 60;
                height = 135;
                objASPJpeg.RotateL();
            }

               //For Other Images
                if ((strMerchantID != null) || (strMerchantID != ""))
                {
                    if (strTemp == "1")
                    {
                       objASPJpeg.OpenBinary((byte[])new BusinessLogic.BLL.Merchant().DownloadTempImage(Sabre.Common.NullHandler.ConvertToLongNullable(strMerchantID), strImageType));
                    }
                    else if(strTemp=="0" || strTemp=="")
                    {
                        if (ctx.Request.QueryString["height"].ToString() == "63")
                        {
                            categoryID = -99;
                            byte[] imageDataArray = new BusinessLogic.BLL.Admin().getPrimaryCategoryImages_Default(categoryID);
                            if (imageDataArray[0] != 0)
                                objASPJpeg.OpenBinary(imageDataArray);
                        }
                        else
                        {
                            if ((strImageType != string.Empty) && (TownID == null) || (TownID == ""))
                                objASPJpeg.OpenBinary((byte[])new BusinessLogic.BLL.Merchant().DownloadImage(Sabre.Common.NullHandler.ConvertToLongNullable(strMerchantID), strImageType, Sabre.Common.NullHandler.NullHandlerForLong(strlocationID, 0)));
                            else
                                if ((TownID != null) || (TownID != ""))
                                    objASPJpeg.OpenBinary((byte[])new BusinessLogic.BLL.AdManagement().DownloadTempImageForTownPage(Sabre.Common.NullHandler.ConvertToInt(TownID)));
                        }
                    }
                    else if (strTemp == "2")
                    {
                        if ((TownID != null) || (TownID != ""))
                            objASPJpeg.OpenBinary((byte[])new BusinessLogic.BLL.AdManagement().DownloadTempImageForHomePage(Sabre.Common.NullHandler.ConvertToInt(TownID)));
                    }
                }
        }

        if (!isCategoryImage)
        {
            hightImageRatio = System.Convert.ToDecimal(height) / System.Convert.ToDecimal(objASPJpeg.OriginalHeight);
            widthImageRatio = System.Convert.ToDecimal(width) / System.Convert.ToDecimal(objASPJpeg.OriginalWidth);

            if ((widthImageRatio <= 0) || ((hightImageRatio < widthImageRatio) && (hightImageRatio > 0)))
            {
                imageRatio = hightImageRatio;
            }
            else
            {
                imageRatio = widthImageRatio;
            }
        }

        if (IsPageID)
        {
            byte[] imageDataArray = new BusinessLogic.BLL.Admin().getDIImages(Convert.ToInt32(DIImageID));
            if (imageDataArray[0] != 0)
                objASPJpeg.OpenBinary(imageDataArray);


        }
        if (Ismarquee)
        {
            byte[] imageDataArray = new BusinessLogic.BLL.Admin().getMarqueeImage(Convert.ToInt32(Marquee_ImageID));
            if (imageDataArray[0] != 0)
                objASPJpeg.OpenBinary(imageDataArray);


        }

        if (tempStrImageType == "couponlogo")
            imageRatio = 0.5M;

        OriginalWidth = objASPJpeg.OriginalWidth;
        OriginalHeight = objASPJpeg.OriginalHeight;


        objASPJpeg.Width = System.Convert.ToInt32(width);
        objASPJpeg.Height = System.Convert.ToInt32(height);
        objASPJpeg.ToRGB();
        objASPJpeg.Quality = 100;

        ctx.Response.Clear();
        ctx.Response.AddHeader("content-disposition", "attachment; filename=test");
        ctx.Response.BinaryWrite((byte[])objASPJpeg.Binary);
        ctx.Response.End();
    }

    catch (Exception ex)
    {

    }
}

public bool IsReusable
{
    get
    {
        return true;
    }
}
}

どんな助けでも大歓迎です。

ありがとうございました!

4

0 に答える 0