【发布时间】:2010-12-18 19:11:31
【问题描述】:
我正在动态创建图像并且需要向用户展示这些图像。 为此,我创建了一个 ashx 文件,但问题是这个 ashx 文件永远不会被调用,不确定为什么路径问题或需要在 web.config 中添加任何标签。 虽然调试它不去..可能是它没有找到 请指教。
编辑:当我直接点击 ashx 网址时,它会显示一些结果
编辑 1:知道会话在上下文中为空是什么原因?
或 MVC asp.net 不需要 ashx 处理程序,请告知。
/// <summary>
/// Summary description for $codebehindclassname$
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class GetImage : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
Log.Info(" In theGetImage");
context.Response.Clear();
byte[] imageByteArray = System.Convert.FromBase64String(context.Session["FrontJpegBase64"].ToString().Replace(' ', '+'));
// System.IO.MemoryStream imageMemoryStream = new System.IO.MemoryStream(imageByteArray);
try
{
using (System.Drawing.Image img = System.Drawing.Image.FromStream(new System.IO.MemoryStream(imageByteArray)))
{
img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
catch (System.Exception ex)
{
}
finally
{
// img.Close();
context.Response.Flush();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
【问题讨论】: