[Mono-list] HttpHandler for *.jpg

Martin Hinks mhinks at gmail.com
Mon Jun 20 11:35:33 EDT 2005


Seems like a bug with passing the QS through to the handler, maybe
file a BugZilla report unless anyone else has more info....

Martin

On 6/20/05, Marc DM <m at phronein.com> wrote:
> After a little bit of debugging,
> I have discovered that when there are QueryString parameters, passed
> such as /images/pic1.jpg?thumb=1 the ProcessRequest method of the
> Handler doesn't get called.
> 
> I added a line to the ProcessRequest medhod to write a log to a text
> file for each iteration of the method. I also added log statements to
> various places in the code.
> 
> After browsing a couple of pages, I realize that every entry in the log
> is an entry for which there is no querystring.
> 
> Below is the code I put in the handler :
> 
> 
> >       public class ImageHandler:IHttpHandler
> >       {
> >
> >               HttpResponse Response;
> >               HttpRequest Request;
> >               HttpServerUtility Server;
> >
> >               #region IHttpHandler Members
> >
> >               public void ProcessRequest(HttpContext context)
> >               {
> >
> >                       //Set global context objects
> >                       Server = context.Server;
> >                       Response = context.Response;
> >                       Request = context.Request;
> >
> >                       //Do the image stuff
> >
> > ///DEBUG
> >                       Log("Beginning image output [QS=" + Request.QueryString.Count.ToString() + "] = " + Request.RawUrl);
> > ///DEBUG
> >
> >                       RequestImage();
> >
> >               }
> >               public bool IsReusable
> >               {
> >                       get{ return true;
> >               }
> >
> > [... rest of the handler code ...]
> >
> 
> And the Logger.
> 
> > //debugging logger
> >     public static void Log (String logMessage)
> >     {
> >
> >       StreamWriter w = File.AppendText("/home/gary/www/mysite/www/images/hih_cache/hih_log.txt");
> >         w.Write("\r\nLog Entry : ");
> >         w.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),
> >             DateTime.Now.ToLongDateString());
> >         w.WriteLine("  :{0}", logMessage);
> >         w.WriteLine ("-------------------------------");
> >         // Update the underlying file.
> >         w.Flush();
> >         w.Close();
> >     }
> 
> Records in the log file were like :
> 
> > Log Entry : 10:02:52 AM Monday, June 20, 2005
> >   :Beginning image output [QS=0] = /images/banner_c1.jpg
> > -------------------------------
> 
> 
> Anyone else having this kinda fun?
> 
> Marc DM
> 
> ---------------
> 
> On Mon, 2005-06-20 at 08:58 +0100, Martin Hinks wrote:
> > What part of the app is failing?
> >
> > Is the handler for .jpg types being called but the querystring is blank?
> >
> > Have you traced through the application? If you can find exactly what
> > is failing we can file BugZilla reports.
> >
> > If the handler is working post some source and I'll take a look later.
> >
> > To find out what's going on add "response.writeline" statements at
> > various points in your code - or try Mono Debugger - although I dont
> > know how advanced it is...
> >
> > Martin
> >
> > On 6/20/05, Marc DM <m at phronein.com> wrote:
> > > (*falling asleep as I type this*)
> > >
> > > I have a HttpHandler that works on .NET but not on Mono. I need some
> > > help to sort it out.
> > >
> > > It is a HttpHandler to allow me to use a url like :
> > >
> > >    http://mysite/images/Beach12/DCS001.JPG?w=200
> > >    to give me the image at the specified url, but proportionately
> > > resized to 200px wide.
> > >
> > >    http://mysite/images/Beach12/DCS001.JPG?thumb=1
> > >    to give me the image at the specified url, resized to a pre-defined
> > > thumbnail size
> > >
> > > etc...
> > >
> > > I have the HttpHandler, written in c#, it compiles on mono (had to
> > > change Response.TransmitFile to Response.WriteFile); no errors.
> > >
> > > It compiles on Windows. No Problem.
> > >
> > > using Microsoft .NET Framework 1.1 when I access
> > > http://mysite/images/Beach12/DCS001.JPG?thumb=1 from my browser, a
> > > thumbnailed version of the photo is created in the cache directory (if
> > > it doesn't already exist, within the site), and then returned to the
> > > browser. It works.
> > >
> > > on Apache/2.0.54 (Debian GNU/Linux) mod_mono/1.0.9
> > > Everything else in the application works beautifully.  But a call to
> > > http://mysite/images/Beach12/DCS001.JPG?thumb=1 returns the full size
> > > image and the QueryString is seemingly ignored.
> > >
> > > My Apache config, mono webapp file,web.config are attached below.
> > >
> > > Can someone clue me in? How can I tell what's happening here.
> > > Thanks.
> > >
> > > Marc DM
> > > -----------------APACHE CONFIG---------------------
> > > ---------------------/etc/apache2/sites-available/mysite----------
> > > NameVirtualHost *:80
> > > <VirtualHost *:80>
> > >        ServerName mysite
> > >        ServerAdmin webmaster at mysite
> > >
> > >        DocumentRoot /home/gary/www/mysite/www/
> > >        AddHandler mono .aspx .ascx .jpg
> > >
> > >        DirectoryIndex default.aspx index.aspx default.html index.html
> > >
> > >        <Directory /home/gary/www/mysite/www/>
> > >                Options FollowSymLinks MultiViews
> > >                Order allow,deny
> > >                allow from all
> > >        </Directory>
> > > </VirtualHost>
> > >
> > > ---------------------/etc/apache2/ mods-available/mono.conf----------
> > >  MonoUnixSocket /tmp/mod_mono_server
> > >  MonoRunXSP true
> > >  MonoApplicationsConfigDir /etc/apache2/mod-mono-applications
> > >  MonoDebug true
> > >
> > > -----------------web.config---------------------
> > >  <system.web>
> > >    ...
> > >    ...
> > >    <httpHandlers>
> > >      <add verb="*" path="*.jpg"
> > > type="Mynamespace.HttpHandlers.ImageHandler,HolmokImageHandler />
> > > </httpHandlers>
> > >
> > > ---------------------------------------------------------------
> > >
> > > _______________________________________________
> > > Mono-list maillist  -  Mono-list at lists.ximian.com
> > > http://lists.ximian.com/mailman/listinfo/mono-list
> > >
> >
> >
> 
> 


-- 
Martin Hinks


More information about the Mono-list mailing list