C# IIS7.5中的ASHX文件不';不工作(不使用ashx打开图像并显示空白)
我需要一些关于IIS7.5中ashx文件的帮助。此应用程序位于VS 2005 windows server 2008中 我正在尝试使用ashx在aspx页面上打开图像。当我在IIS 6.0中创建网站时,检索到的图像显示得很好。在我将其移动到IIS7.5之后,ashx文件无法工作,从某种意义上说,图像无法显示C# IIS7.5中的ASHX文件不';不工作(不使用ashx打开图像并显示空白),c#,asp.net,ashx,C#,Asp.net,Ashx,我需要一些关于IIS7.5中ashx文件的帮助。此应用程序位于VS 2005 windows server 2008中 我正在尝试使用ashx在aspx页面上打开图像。当我在IIS 6.0中创建网站时,检索到的图像显示得很好。在我将其移动到IIS7.5之后,ashx文件无法工作,从某种意义上说,图像无法显示 www.website.com/imageout.ashx?height=63&width=42&categoryID=15&imageID=77 我在谷歌上搜索并
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;
}
}
}
使用制度;
使用System.Web;
公共类imageout:IHttpHandler
{
公共无效处理请求(HttpContext ctx)
{
字符串strmerchanti=“”;
字符串strImageType=“”;
字符串strTemp=“”;
字符串strlocationID=“”;
string strcouponID=string.Empty;
int categoryID=0;
字符串PageID=“”;
字符串DIImageID=“”;
int-imageID=0;
字符串选框_ImageID=“”;
bool-Ismarquee=false;
bool isCategoryImage=false;
bool IsPageID=false;
long?couponID=0;
//*
字符串TownID=“”;
//*
int-ImageID=0;
if(ctx.Request.QueryString[“MerchantID”]!=null)
{
strmerchanti=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[“RegionMarqueId”].ToString();
Ismarquee=true;
}
//*
//TownID=“151531”;
字符串tempStrImageType=strImageType;
如果(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;
}
整数宽度=0;
整数高度=0;
如果(TownID!=“”)
{
如果(TownID!=“0”)
{
如果(strTemp==“0”)
{
宽度=720;高度=240;
}
其他的
{
宽度=250;高度=194;
}
}
其他的
{
宽度=259;高度=352;
}
}
否则如果(PageID!=“”)
{
宽度=250;高度=150;
}
else if(选框_ImageID!=“”)
{
宽度=475;高度=75;
}
其他的
{
宽度=100;高度=50;
}
十进制高位激励;
小数比;
内部原始宽度;
内部原始高度;
十进制图像比率;
字节[]图像数据;
尝试
{
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=新的ASPJPEGLib.ASPJpegClass();
if(categoryID!=0&&imageID!=0)
{
byte[]imageDataArray=new BusinessLogic.BLL.Admin().getPrimaryCategoryImages(categoryID,imageID);
如果(imageDataArray[0]!=0)
OpenBinary(imageDataArray);
}
其他的
{
if(couponID!=0)
{
OpenBinary(newBusinessLogic.BLL.优惠券().GetBinaryBarcodeImage(couponID));
宽度=60;
高度=135;
objASPJpeg.RotateL();
}
//对于其他图像
if((strmerchandit!=null)| |(strmerchandit!=“”)
{
如果(strTemp==“1”)
{
OpenBinary((字节[])new BusinessLogic.BLL.Merchant().DownloadTempImage(Sabre.Common.NullHandler.ConvertToLongNullable(strmerchandi),strImageType));
}
else if(strTemp==“0”| | strTemp==”“)
{
if(ctx.Request.QueryString[“height”].ToString()=“63”)
{
类别ID=-99;
byte[]imageDataArray=new BusinessLogic.BLL.Admin().getPrimaryCategoryImages\u默认值(categoryID);
if(imag