dynamic image (from db) using Generic Handler

后端 未结 1 846
青春惊慌失措
青春惊慌失措 2020-12-22 06:47

I\'m trying to using a Generic Handler to retrieve and display images that are stored in a database.

But its just not working. Ive tried verious of the code below, b

相关标签:
1条回答
  • 2020-12-22 07:16

    wow, ok. Not sure how much of that is old code, what should be commented out or w/e but try something like this:

    public void ProcessRequest (HttpContext context) {
        int iconId;
    
        if (string.IsNullOrEmpty(context.Request.QueryString["id"]) || !int.TryParse(context.Request.QueryString["id"], out iconId) )
            throw new ArgumentException("No parameter specified");
    
        context.Response.ContentType = "image/gif";
    
        var db = new UdINaturen.UdINaturenContext();
    
        var GetIcon = (from i in db.subcategoryicons
                       where i.id == iconId
                       select i.picture).FirstOrDefault();
        byte[] buffer = (byte[])Convert.FromBase64String(GetIcon);
    
        context.Response.ContentType = "image/gif";
        context.Response.BinaryWrite(buffer);
        context.Response.Flush();
    }
    
    0 讨论(0)
提交回复
热议问题