This project has moved. For the latest updates, please go here.

How do I use the HttpHandler for an ASP.NET application?

The HttpHandler is used when caching the rendered map image. To enable the HttpHandler, add the following to your web.config:
<configuration xmlns="">
            <add verb="*" path="GetMap.aspx" type="SharpMap.Web.HttpHandler,SharpMap"/>
To show your map in a webpage, set the ImageUrl of your asp:Image control:
string imgID = SharpMap.Web.Caching.InsertIntoCache(5, myMap.GetMap(), Session.SessionID, Context);
imgMap.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);

The HttpHandler is using the ASP.NET cache which seem to perform differently on different servers. Often the result is that images are removed from the cache too soon, and thus SharpMap is not able to retrieve it.

The recommended approach would be to instead create a dedicated handler that renders the map when requested. This can either be accomplished by embedding nessesary values in the querystring to the handler (ex. getmap.ashx?width=300&height=150&center=23,34&zoom=450), or to store these values in session-variables and retrieve them prior to rendering the map. This dedicated handler should call the myMap.GetMap() method and stream the generated image directly to the client.

Last edited Aug 31, 2012 at 12:17 PM by FObermaier, version 6