using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Xml;
using System.Web;
using System.Configuration;
public class generate_qrcode : System.Web.Routing.IRouteHandler
{
public IHttpHandler GetHttpHandler(System.Web.Routing.RequestContext requestContext)
{
HttpHandler MyhttpHandler = new HttpHandler();
return MyhttpHandler;
}
public class HttpHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(System.Web.HttpContext context)
{
System.Net.ServicePointManager.DefaultConnectionLimit = 65535;
string sid = HttpContext.Current.Request.QueryString["sid"];
if ((sid == null))
{
return;
}
try
{
MemoryStream Myinput = new MemoryStream(Utils.GenerateRandomQRCode());
byte[] Buffer = null;
Buffer = new byte[Myinput.Length + 1];
Myinput.Read(Buffer, 0, Buffer.Length);
Myinput.Close();
Myinput.Dispose();
context.Response.Clear();
context.Response.ContentType = "image/png";
context.Response.AddHeader("Content-Type", "image/png");
context.Response.AddHeader("Content-Length", Buffer.Length.ToString());
context.Response.AddHeader("Content-Transfer-Encoding", "binary");
context.Response.BinaryWrite(Buffer);
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetAllowResponseInBrowserHistory(false);
context.Response.Flush();
context.Response.Close();
GC.Collect();
}
catch (Exception ex)
{
// Error Handling (Depending on what and how you return to the call, you best deal with the exception here
NoImage(context);
return;
}
}
public void NoImage(System.Web.HttpContext context)
{
// Stream no image
FileStream Myinput = new FileStream(ConfigurationManager.AppSettings("NoImage"), FileMode.Open, FileAccess.Read);
byte[] Buffer = null;
Buffer = new byte[Myinput.Length + 1];
Myinput.Read(Buffer, 0, Buffer.Length);
Myinput.Close();
Myinput.Dispose();
context.Response.Clear();
context.Response.ContentType = "image/png";
context.Response.AddHeader("Content-Type", "image/png");
context.Response.AddHeader("Content-Length", Buffer.Length.ToString());
context.Response.AddHeader("Content-Transfer-Encoding", "binary");
context.Response.BinaryWrite(Buffer);
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetAllowResponseInBrowserHistory(false);
context.Response.Flush();
context.Response.Close();
GC.Collect();
}
}
}