嗨我写了这个图像处理程序代码,它在我的本地工作正常,并在页面中显示图像,现在我已经上传到主机,当我从远程请求页面图像不显示在图像控制中!任何帮助?!Imagehandler不显示来自远程请求的图像
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Web;
public class Handler : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["IranQRDBConnectionString"].ConnectionString);
public void ProcessRequest(HttpContext context)
{
try
{
string TableName = context.Session["TableToQuery"].ToString();
string ID = context.Session["ID"].ToString();
SqlCommand comm = new SqlCommand("SELECT * FROM " + TableName + " WHERE ID=" + ID, conn);
conn.Open();
SqlDataReader dr = comm.ExecuteReader();
dr.Read();
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite((byte[])dr["Image"]);
conn.Close();
}
catch
{
SqlCommand comm = new SqlCommand("SELECT * FROM DefaultImage WHERE ID=1", conn);
conn.Open();
SqlDataReader dr = comm.ExecuteReader();
dr.Read();
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite((byte[])dr["Image"]);
conn.Close();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
我的ConnectionString:
<add name="ConnectionString" connectionString="Data Source=myDatasource;Initial Catalog=DB;User Id=myusername;Password=mypassword"
providerName="System.Data.SqlClient" />
,这里是在至极DataList控件我显示图像:
'/> “>
我检查我的数据库中,数据被正确地插入文本数据回发到我的网页,但只有图像显示不出来
,这里是我的webconfig的一部分:
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ScriptModule"/>
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory"/>
<remove name="ScriptHandlerFactoryAppServices"/>
<remove name="ScriptResource"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</handlers>
</system.webServer>
你有没有添加处理路径哈德勒部分,连接字符串到新的数据库? IIS版本是一样的吗?尝试在声明自己之前清理先前注册的处理程序。 – user854301 2012-08-06 07:49:22
@ user854301不,我没有添加任何连接字符串,我不知道如何做到这一点:(你会帮助我PLZ – Karamafrooz 2012-08-06 07:52:41
首先检查“IranQRDBConnectionString”连接字符串持续在您的web.config \ connectionStrings。比你可以验证你的web .config \ system.webServer \ handlers部分 – user854301 2012-08-06 07:58:02