예제 #1
0
		public void ProcessRequest(HttpContext context) {
			if(context == null)
				throw new ArgumentNullException("context");
			var encstr = context.Request["encstr"];
			//string encimage	= context.Request["encimage"];
			//string encanchor	= context.Request["encanchor"];

			if(encstr != null) {
				// See if client has a cached version of the image
				var ifModifiedSince = context.Request.Headers.Get("If-Modified-Since");
				// If so, always let the client use the cached version cause this image shall not change ever.
				if(ifModifiedSince != null) {
					context.Response.StatusCode = 304;
					context.Response.End();
				}
				using(var image = new EmailImage()) {
					image.Email = Encoding.UTF8.GetString(Convert.FromBase64String(encstr));
					image.RenderImage(context.Response.OutputStream); //Render image to output stream
				}
				context.Response.ContentType = "image/gif";
				context.Response.StatusCode = 200;
				context.Response.Cache.SetLastModified(DateTime.Now);
				context.Response.Cache.SetCacheability(HttpCacheability.Public);
				context.Response.Cache.SetValidUntilExpires(true);
				context.Response.Cache.VaryByParams["*"] = true;
			} else {
				context.Response.StatusCode = 404;
			}
		}
예제 #2
0
        public void ProcessRequest(HttpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            var encstr = context.Request["encstr"];

            //string encimage	= context.Request["encimage"];
            //string encanchor	= context.Request["encanchor"];

            if (encstr != null)
            {
                // See if client has a cached version of the image
                var ifModifiedSince = context.Request.Headers.Get("If-Modified-Since");
                // If so, always let the client use the cached version cause this image shall not change ever.
                if (ifModifiedSince != null)
                {
                    context.Response.StatusCode = 304;
                    context.Response.End();
                }
                using (var image = new EmailImage()) {
                    image.Email = Encoding.UTF8.GetString(Convert.FromBase64String(encstr));
                    image.RenderImage(context.Response.OutputStream);                     //Render image to output stream
                }
                context.Response.ContentType = "image/gif";
                context.Response.StatusCode  = 200;
                context.Response.Cache.SetLastModified(DateTime.Now);
                context.Response.Cache.SetCacheability(HttpCacheability.Public);
                context.Response.Cache.SetValidUntilExpires(true);
                context.Response.Cache.VaryByParams["*"] = true;
            }
            else
            {
                context.Response.StatusCode = 404;
            }
        }