嗨,我编写了这个图像处理程序代码,它在我的本地工作正常并在页面中显示图像,现在我已将其上传到主机上,当我从远程请求页面时,图像不会显示在图像控件中!有什么帮助吗?!
<%@ 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;
}
}
}
我的连接字符串:
<add name="ConnectionString" connectionString="Data Source=myDatasource;Initial Catalog=DB;User Id=myusername;Password=mypassword"
providerName="System.Data.SqlClient" />
这是我显示图像的数据列表:
' /> '>
我检查了我的数据库,数据插入正确,文本数据回发到我的页面,但只有图像没有显示
这是我的 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>