Sto utilizzando un gestore di richiesta ashx per recuperare le immagini e il mio punto di interruzione nel file ashx non viene colpito. Quando uso firebug posso vedere che la richiesta restituisce un 404, il che mi fa pensare che ho bisogno di configurare alcune impostazioni in modo da poter trovare il file ashx.asp.net richiesta ashx 404
Utilizzo Visual Studio 2008 e .net 3.5.
file di ASHX
namespace hybrid.content.Handlers
{
public class DB_Images : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
Int32 image_id;
if (context.Request.QueryString["id"] != null)
image_id = Convert.ToInt32(context.Request.QueryString["id"]);
else
throw new ArgumentException("No parameter specified");
context.Response.ContentType = "image/jpeg";
Stream strm = GetImageFromDatabase(image_id);
if (strm != null)
{
byte[] buffer = new byte[4096];
int byteSeq = strm.Read(buffer, 0, 4096);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 4096);
}
//context.Response.BinaryWrite(buffer);
}
}
public Stream GetImageFromDatabase(int image_id)
{
SqlConnectionStringBuilder connstr = new SqlConnectionStringBuilder();
//connstr.InitialCatalog = "dummy";
//connstr.UserID = "sa";
//connstr.Password = "password";
//connstr.DataSource = "source";
connstr.InitialCatalog = "smsdb";
connstr.UserID = "user";
connstr.Password = "password";
connstr.DataSource = "10.31.4.79";
SqlConnection conn = new SqlConnection(connstr.ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
// cmd.CommandText = "select image from cis_images where image_id = @p_image_id";
cmd.CommandText = "select image from test_images where image_id = @p_image_id";
cmd.Parameters.AddWithValue("@p_image_id", image_id);
conn.Open();
object img = cmd.ExecuteScalar();
try
{
return new MemoryStream((byte[])img);
}
catch
{
return null;
}
finally
{
conn.Close();
conn.Dispose();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
evento Pagina click
protected void Button1_Click(object sender, EventArgs e)
{
Image1.ImageUrl = "~/DB_Images.ashx?id=" + TextBox1.Text;
}
ashx html
<%@ WebHandler Language="C#" CodeBehind="DB_Images.ashx.cs" Class="hybrid.content.Handlers.DB_Images" %>
Non c'è alcun html a parte questo riferimento.
C'è qualcosa che mi manca per farlo funzionare?
Potresti incollare ciò che hai nella vista "html" del gestore? (il contenuto del file ashx) –
È l'installazione di IIS per servire i gestori? –
@TheSavage IIS è configurato per servire gestori. –