我现在有将我的网站部署到共享Windows主机的问题。IHttpHandler在部署到Web服务器后不加载图像
我目前正在托管它与hostgator。
问题是,我的ThumbnailHandler应该返回一个图像文件,一旦项目被部署到网络服务器,就停止工作。它在本地IIS虚拟文件夹和vs2010调试中正常工作。
e.g-
http://www.myweb.com/imageHandler.ashx?i=0 - ERROR
http://www.myweb.com/imageHandler.ashx - ERROR
http://www.myweb.com/image-handler?i=0 - (路由与IRouteHandler) ERROR
不引发任何异常。如果我打开网址,则返回'图像(路径)无法显示,因为它包含错误'。
ThumbnailHandler.ashx
public void ProcessRequest(HttpContext context) {
context.Response.Flush();
Size maxSize = new Size(98, 98);
byte[] buffer = Imaging.GetImage(context.Server.MapPath("~/img/noimage98.png"), maxSize).GetBytes(System.Drawing.Imaging.ImageFormat.Jpeg);
try {
Int32 index = GetImageIndex(context);
maxSize = GetMaxSize(context);
if (index < 0 || maxSize == null)
throw new Exception("Index size is not specified.");
String authToken = GetAuthenticationToken(context);
DirectoryInfo directoryInfo = AdvertisementDirectory.GetDirectoryInfo(authToken);
List<FileInfo> fileInfos = AdvertisementDirectory.GetImageFileInfoList(directoryInfo);
using (System.Drawing.Image thumbnailImage = Imaging.GetImage(fileInfos[index].FullName, maxSize)) {
buffer = thumbnailImage.GetBytes(System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
catch (Exception ex) {
throw ex;
}
finally {
context.Response.ContentType = "image/jpeg";
context.Response.OutputStream.Write(buffer, 0, buffer.Length);
context.Response.Flush();
context.Response.Close();
context.ApplicationInstance.CompleteRequest();
}
}
public bool IsReusable { get { return false; } }
的web.config
<globalization requestEncoding="iso-8859-1" responseEncoding="iso-8859-1" fileEncoding="utf-8" culture="en-US" uiCulture="en-US"/>
<pages buffer="true" clientIDMode="Static" controlRenderingCompatibilityVersion="4.0" enableViewStateMac="true" validateRequest="true" enableEventValidation="true" enableSessionState="true" viewStateEncryptionMode="Auto" >
<controls>
<add tagPrefix="ATK" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
</controls>
</pages>
<httpHandlers>
<add verb="*" path="*.ashx" type="Tradepost.ThumbnailHandler, Tradepost"/>
</httpHandlers>
<httpRuntime executionTimeout="600" maxRequestLength="40000" maxUrlLength="260" maxQueryStringLength="2048" requestLengthDiskThreshold="80" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="5000" enableKernelOutputCache="true" enableVersionHeader="true" requireRootedSaveAsPath="true" enable="true" shutdownTimeout="90" delayNotificationTimeout="5" waitChangeNotification="0" maxWaitChangeNotification="0" enableHeaderChecking="true" sendCacheControlHeader="true" apartmentThreading="false" requestPathInvalidCharacters="<,>,*,%,&,:,\,?" />
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
有没有人经历过这个?我也试着检查文件夹权限安全设置。任何帮助表示赞赏,在此先感谢。
注意:这发生在任何文件夹中的任何图像。
因此,如果我使用'FromFile',则不会使用'FromStream',而是解决此信任问题。 – choz