[Mono-dev] Problems with IHttpHandler

Nik Radford nik at terminaldischarge.net
Fri Feb 22 10:22:28 EST 2008


Yes. I added
  MonoServerPath /usr/local/bin/mod-mono-server2

to the mod_mono.conf file before attempting this.

However, I've just been trying to create the test case, by creating a test
site and dll, and don't seem to be able to replicate the error. So now I'm
even more confused.


> Hi!
>
> Are you sure you run it with mod_mono_server2 rather than the default
> mod_mono_server?
>
> Cheers,
> Michał Ziemski
>
> Nik Radford pisze:
>> Yes, this I've already done.
>>
>> Basically I'm doing a catch all for the http handler, the entry for my
>> web
>> config looks like so
>>
>>     <httpHandlers>
>>         <add path="*" verb="*"
>> type="TerminalDischarge.Web.HttpHandler.HttpHandler,
>> TerminalDischarge.Web"/>
>>     </httpHandlers>
>>
>> I'm using for URL rewritting. and the HttpHandler i'm using looks like
>> this:
>>
>> (sorry if its a bit much, I just copy pasted the whole file)
>>
>> using System;
>> using System.Collections.Generic;
>> using System.Configuration;
>> using System.IO;
>> using System.Text;
>> using System.Web;
>> using System.Web.UI;
>> using System.Xml;
>> using TerminalDischarge.Web.Mapping;
>>
>> namespace TerminalDischarge.Web.HttpHandler
>> {
>>     public class HttpHandler : IHttpHandler
>>     {
>>         #region Internals
>>         private readonly List<Map> m_Maps;
>>         #endregion
>>
>>         #region Constructors
>>         public HttpHandler()
>>         {
>>             m_Maps = new List<Map>();
>>         }
>>         #endregion
>>
>>         #region Public Members
>>         ///<summary>
>>         ///Enables processing of HTTP Web requests by a custom
>> HttpHandler
>> that implements the <see cref="T:System.Web.IHttpHandler"></see>
>> interface.
>>         ///</summary>
>>         ///
>>         ///<param name="context">An <see
>> cref="T:System.Web.HttpContext"></see> object that provides
>> references to the intrinsic server objects (for example, Request,
>> Response, Session, and Server) used to service HTTP requests.
>> </param>
>>         public void ProcessRequest(HttpContext context)
>>         {
>>             AddPaths(context);
>>             string url = context.Request.Path;
>>
>>             foreach (Map m in m_Maps)
>>             {
>>                 if (m.DoesMatch(url))
>>                 {
>>                     string destination = m.MapUrl(url);
>>                     try
>>                     {
>>                         string fileName =
>> context.Server.MapPath(destination);
>>
>>                         Page page =
>> PageParser.GetCompiledPageInstance(destination,
>> fileName, context) as Page;
>>                         if (page != null)
>>                         {
>>                             context.RewritePath(destination);
>>                             page.ProcessRequest(context);
>>                             return;
>>                         }
>>                     }
>>                     catch (HttpException)
>>                     {
>>                         PageNotFound(context);
>>                         return;
>>                     }
>>                 }
>>             }
>>
>>             {
>>                 //no match found, so palm off to default handler
>>                 System.Web.DefaultHttpHandler defaultHttpHandler = new
>> DefaultHttpHandler();
>>                 defaultHttpHandler.BeginProcessRequest(context, null,
>> null);
>>                 return;
>>             }
>>         }
>>         #endregion
>>
>>         #region Private Members
>>         /// <summary>
>>         /// Displays a simple error if a path isn't found
>>         /// </summary>
>>         /// <param name="context"></param>
>>         private void PageNotFound(HttpContext context)
>>         {
>>             context.Response.StatusCode = 404;
>>             context.Response.Write(string.Format("The page {0} was not
>> found", context.Request.Path));
>>         }
>>
>>
>>         /// <summary>
>>         /// Parses the path mapping file and populates the map list
>>         /// </summary>
>>         /// <param name="context">An <see
>> cref="T:System.Web.HttpContext"></see> object that provides
>> references to the
>>         /// intrinsic server objects (for example, Request, Response,
>> Session, and Server) used to service HTTP requests. </param>
>>         private void AddPaths(HttpContext context)
>>         {
>>
>>             m_Maps.Clear();
>>
>>             //get mapping filename
>>             string mapFile =
>> context.Server.MapPath(ConfigurationManager.AppSettings["PathMap"]);
>>
>>             //Load it
>>             XmlDocument xDoc = new XmlDocument();
>>             xDoc.Load(mapFile);
>>             XmlNodeList mapNodes = xDoc.SelectNodes("/Mapping/Map");
>>
>>             //we should get back a list of all our document mapping
>>             //parse it and populate our map list
>>             foreach (XmlNode node in mapNodes)
>>             {
>>                 XmlNode xSearchFor =
>> node.SelectSingleNode("./SearchFor");
>>                 XmlNode xSendTo = node.SelectSingleNode("./SendTo");
>>
>>                 if (xSearchFor != null && xSendTo != null)
>>                 {
>>                     string searchFor = xSearchFor.InnerText.Replace("~",
>> context.Request.ApplicationPath);
>>                     string sendTo = xSendTo.InnerText.Replace("~",
>> context.Request.ApplicationPath);
>>                     Map map = new Map(searchFor, sendTo);
>>                     m_Maps.Add(map);
>>                 }
>>             }
>>
>>         }
>>         #endregion
>>
>>         #region Properties
>>         ///<summary>
>>         ///Gets a value indicating whether another request can use the
>> <see cref="T:System.Web.IHttpHandler"></see> instance.
>>         ///</summary>
>>         ///
>>         ///<returns>
>>         ///true if the <see cref="T:System.Web.IHttpHandler"></see>
>> instance is reusable; otherwise, false.
>>         ///</returns>
>>         ///
>>         public bool IsReusable
>>         {
>>             get { return true; }
>>         }
>>
>>         #endregion
>>     }
>> }
>>
>>
>>
>>> Hi!
>>>
>>> I assume you precompile the assambly and put it in bin.
>>> In this case you sould put the name of the assembly in httpHandlers
>>> section in web.config
>>>
>>> Let's say the assembly is named "fooAssembly.dll". In that case add:
>>> <httpHandlers>
>>>       <add verb="POST" path="Execute" type="NamespaceMyType,
>>> fooAssembly"/>
>>> </httpHandlers>
>>>
>>> If that doesn't help, please, post some code and the contents of
>>> web.config.
>>>
>>> Cheers,
>>> MichaÃ
‚ Ziemski
>>>
>>> Nik Radford pisze:
>>>
>>>> Hello all,
>>>>
>>>> I was wondering if someone could help me with this.
>>>> I've written an ASP.NET website using visual studio 2005, and have
>>>> written
>>>> my own custom IHttpHandler. All works well, except when I move it over
>>>> to
>>>> my linux server and run it under mono.
>>>>
>>>> I get the error "(my http handler type) does not implement
>>>> IHttpHandler
>>>> or
>>>> IHttpHandlerFactory"
>>>>
>>>> I then wrote a little program which I compiled under mono, to load the
>>>> assembly my IHttpHandler type is in, and make sure that IHttpHandler
>>>> could
>>>> indeed be assigned from my type.
>>>>
>>>>     typeof(IHttpHandler).IsAssignableFrom(t);
>>>>
>>>> returned true.
>>>>
>>>> So I'm a little lost as to what is happening here.
>>>>
>>>> thanks in advance.
>>>>
>>>> Nik.
>>>>
>>>> ------------------------------------------
>>>> E-Mail:    Nik at Terminaldischarge.net
>>>> (We)Blog:  http://blog.terminaldischarge.net
>>>>
>>>> _______________________________________________
>>>> Mono-devel-list mailing list
>>>> Mono-devel-list at lists.ximian.com
>>>> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>>>>
>>>>
>>>
>>
>>
>> Nik.
>>
>> ------------------------------------------
>> E-Mail:    Nik at Terminaldischarge.net
>> (We)Blog:  http://blog.terminaldischarge.net
>>
>>
>
>


Nik.

------------------------------------------
E-Mail:    Nik at Terminaldischarge.net
(We)Blog:  http://blog.terminaldischarge.net



More information about the Mono-devel-list mailing list