【发布时间】:2013-06-13 11:19:39
【问题描述】:
我现在在将我的网站部署到共享 Windows 主机时遇到问题。
我目前正在使用 hostgator 托管它。
问题是,我应该返回图像文件的 ThumbnailHandler 在项目部署到网络服务器后停止工作。它在本地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 路由) 错误
不抛出异常。如果我打开网址,它会返回“图像(路径)无法显示,因为它包含错误”。
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>
以前有人经历过吗?我还尝试检查文件夹权限安全设置。任何帮助表示赞赏,在此先感谢。
注意:任何文件夹中的任何图像都会出现这种情况。
【问题讨论】:
标签: c# asp.net shared-hosting