我现在在将我的网站部署到共享 Windows 主机时遇到问题。
我目前正在使用 hostgator 托管它。
问题是,我的 ThumbnailHandler 应该返回一个图像文件,一旦项目部署到 web server就停止工作。它在本地 IIS虚拟文件夹和vs2010 调试中正常工作。
例如-
http://www.myweb.com/imageHandler.ashx?i=0 -错误
http://www.myweb.com/imageHandler.ashx -错误
http://www.myweb.com/image-handler?i=0 - (使用 IRouteHandler 路由) 错误
不会抛出异常。如果我打开 url,它会返回“无法显示图像(路径),因为它包含错误”。
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; } }
网络配置
<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>
有谁之前经历过这个吗?我还尝试检查文件夹权限安全设置。任何帮助表示赞赏,在此先感谢。
注意:这发生在任何文件夹中的任何图像上。