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="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    <system.web>
        <httpHandlers>
            <add verb="*" path="GetMap.aspx" type="SharpMap.Web.HttpHandler,SharpMap"/>
        </httpHandlers>
    </system.web>
</configuration>
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);

Note:
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 1:17 PM by FObermaier, version 6