image handler class method over riding ?

Topics: Controls
Nov 18, 2011 at 7:36 PM
Edited Nov 18, 2011 at 7:38 PM

In a bid to control the custom image display (Blog Engine handles the axd way) i am thinking to override ProcessRequest(HttpContext context) via BlogEngine.Net extension.Could you mind how is that gonna work ?

What i am thinking is -

1.Passing the image url to my custom image resize handler (ashx) such  that , before it is accessed via image.axd?picture=path , the image is already resized by the handler.

2.I have had also tested the resizing of axd generated image by putting whole image in stream and then resizing it via a handler but that perhaps may slow the application.


Is that over riding possible via Extensions ? Any ideas or suggestions or snippets is a welcome..

This one is that handler class method i saw in BE source that controls image rendering process..

 public void ProcessRequest(HttpContext context)
        {
            if (!string.IsNullOrEmpty(context.Request.QueryString["picture"]))
            {
                string file = context.Request.QueryString["picture"];
                OnServing(file);
                try
                {
                    string path = string.Format("{0}/files/", Blog.CurrentInstance.StorageLocation);
                    FileInfo info = new FileInfo(context.Server.MapPath(path) + file);
                    if (info.Exists && info.Directory.FullName.ToUpperInvariant().Contains(string.Format("{0}FILES", Path.DirectorySeparatorChar)))
                    {
                        context.Response.Cache.SetCacheability(HttpCacheability.Public);
                        context.Response.Cache.SetExpires(DateTime.Now.AddYears(1));
                        if (!Utils.SetConditionalGetHeaders(info.CreationTimeUtc))
                        {
                            int startIndex = file.LastIndexOf(".") + 1;
                            string strA = file.Substring(startIndex).ToUpperInvariant();
                            context.Response.ContentType = (string.Compare(strA, "JPG") == 0) ? "image/jpeg" : string.Format("image/{0}", strA);
                            context.Response.TransmitFile(info.FullName);
                            OnServed(file);
                        }
                    }
                    else
                    {
                        OnBadRequest(file);
                        context.Response.Redirect(string.Format("{0}error404.aspx", Utils.AbsoluteWebRoot));
                    }
                }
                catch (Exception exception)
                {
                    OnBadRequest(exception.Message);
                    context.Response.Redirect(string.Format("{0}error404.aspx", Utils.AbsoluteWebRoot));
                }
            }
        }

 public void ProcessRequest(HttpContext context)
        {
            if (!string.IsNullOrEmpty(context.Request.QueryString["picture"]))
            {
                string file = context.Request.QueryString["picture"];
                OnServing(file);
                try
                {
                    string path = string.Format("{0}/files/", Blog.CurrentInstance.StorageLocation);
                    FileInfo info = new FileInfo(context.Server.MapPath(path) + file);
                    if (info.Exists && info.Directory.FullName.ToUpperInvariant().Contains(string.Format("{0}FILES", Path.DirectorySeparatorChar)))
                    {
                        context.Response.Cache.SetCacheability(HttpCacheability.Public);
                        context.Response.Cache.SetExpires(DateTime.Now.AddYears(1));
                        if (!Utils.SetConditionalGetHeaders(info.CreationTimeUtc))
                        {
                            int startIndex = file.LastIndexOf(".") + 1;
                            string strA = file.Substring(startIndex).ToUpperInvariant();
                            context.Response.ContentType = (string.Compare(strA, "JPG") == 0) ? "image/jpeg" : string.Format("image/{0}", strA);
                            context.Response.TransmitFile(info.FullName);
                            OnServed(file);
                        }
                    }
                    else
                    {
                        OnBadRequest(file);
                        context.Response.Redirect(string.Format("{0}error404.aspx", Utils.AbsoluteWebRoot));
                    }
                }
                catch (Exception exception)
                {
                    OnBadRequest(exception.Message);
                    context.Response.Redirect(string.Format("{0}error404.aspx", Utils.AbsoluteWebRoot));
                }
            }
        }
Nov 25, 2011 at 11:33 AM

No answers..