This is the definitive answer to your question:<br><a href="http://ASP.NET">ASP.NET</a> Qick Example, incomplete:  doesn&#39;t handle memory - <b>you must dispose all</b>...<br><br><span style="font-family: courier new,monospace;">&lt;%@ Page Language=&quot;C#&quot; %&gt;<br>

&lt;%@ Import Namespace=&quot;OSGeo.MapGuide&quot; %&gt;<br><br>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>&quot;&gt;<br>

<br>&lt;script runat=&quot;server&quot;&gt;<br>private string _strSessionId = &quot;&quot;;<br>    private string _mapName = &quot;&quot;;<br>    string _csvShowLayers = &quot;&quot;;<br>    string _csvHideLayers = &quot;&quot;;<br>

<br>    protected string GetMapName()<br>    {<br>        return _mapName;<br>    }<br>    protected string GetMapSession()<br>    {<br>        return _strSessionId;<br>    }<br>    protected string GetShowlayers()<br>    {<br>

        return _csvShowLayers;<br>    }<br>    protected string GetHidelayers()<br>    {<br>        return _csvHideLayers;<br>    }<br><br>    protected void Page_Load(object sender, EventArgs e)<br>    {<br><br>        MgUserInformation userInfo = null;<br>

        MgSiteConnection siteConnection = null;<br>        MgSite site = null;<br>        MgResourceIdentifier resourceId = null;<br>        MgMappingService mappingService = null;<br><br>        MgMap map = null;<br>        MgResourceService resourceService = null;<br>

        MgSelection selection = null;<br><br>        MgLayerCollection lColl = null;<br>        MgLayerBase layerBase = null;<br>        MgResourceIdentifier sessionIdResourceIdentifier = null;<br><br>        //TODO: fullfill catch / fullfill finally<br>

        //IMPORTANT: dispose all in finally!!!<br>        try<br>        {<br>            userInfo = new MgUserInformation(&quot;Anonymous&quot;, &quot;&quot;);<br>            siteConnection = new MgSiteConnection();<br>
            siteConnection.Open(userInfo);<br>
<br>            site = siteConnection.GetSite();<br>            _strSessionId = site.CreateSession();<br><br>            //---------------------------------------------------<br>            //Save new mapguide session<br>

            userInfo.SetMgSessionId(_strSessionId);<br>            //---------------------------------------------------<br><br>            resourceId = new MgResourceIdentifier(&quot;Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition&quot;);<br>

            _mapName = resourceId.GetName();<br><br>            //------------------------------------------------<br>            //Layers objectId<br>            mappingService = (MgMappingService)siteConnection.CreateService(MgServiceType.MappingService);<br>

            map = new MgMap();<br>            resourceService = siteConnection.CreateService(MgServiceType.ResourceService) as MgResourceService;<br>            map.Create(resourceService, resourceId, _mapName);<br><br>            lColl = map.GetLayers();<br>

            int iMax = lColl.Count;<br><br>            //Let&#39;s show only Districts:<br>            int iHid = 0, iShow = 0; ;<br>            for (int i = 0; i &lt; iMax; ++i)<br>            {<br>                if (null != layerBase) layerBase.Dispose();<br>

                layerBase = lColl[i];<br>                string layername = layerBase.GetName();<br>                if (layername == &quot;Districts&quot;)<br>                {<br>                    if (iShow &gt; 0) _csvShowLayers += &quot;,&quot;;<br>

                    _csvShowLayers += layerBase.GetObjectId();<br>                    ++iShow;<br>                }<br>                else if (layername == &quot;Hydrography&quot;)<br>                {<br>                    if (iShow &gt; 0) _csvShowLayers += &quot;,&quot;;<br>

                    _csvShowLayers += layerBase.GetObjectId();<br>                    ++iShow;<br>                }<br>                else<br>                {<br>                    //TODO: use StringBuilder<br>                    if (iHid &gt; 0) _csvHideLayers += &quot;,&quot;;<br>

                    _csvHideLayers += layerBase.GetObjectId();<br>                    ++iHid;<br>                }<br>            }<br>            //------------------------------------------------<br><br>            //------------------------------------------------<br>

            //Necessary to show maps:<br>            selection = new MgSelection(map);<br>            selection.Save(resourceService, _mapName);<br><br>            sessionIdResourceIdentifier = new MgResourceIdentifier(<br>

                String.Concat(&quot;Session:&quot;, _strSessionId, &quot;//&quot;, _mapName, &quot;.&quot;, MgResourceType.Map));<br>            map.Save(resourceService, sessionIdResourceIdentifier);<br>            //------------------------------------------------<br>

        }<br>        catch<br>        {<br>            throw;//TODO: Handle exceptions<br>        }<br>        finally<br>        {<br>            //TODO: dispose<br>        }<br>    }</span><span style="font-family: courier new,monospace;"><br>

&lt;/script&gt;<br><br>&lt;html xmlns=&quot;<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>&quot;&gt;<br>&lt;head runat=&quot;server&quot;&gt;<br>    &lt;title&gt;&lt;/title&gt;<br>    &lt;script type=&quot;text/javascript&quot; src=&quot;<a href="http://www.openlayers.org/api/OpenLayers.js">http://www.openlayers.org/api/OpenLayers.js</a>&quot;&gt;&lt;/script&gt;<br>

    &lt;style type=&quot;text/css&quot;&gt;<br>    #map_mg<br>    {<br>        width: 500px;<br>        height:500px;<br>        float: left;<br>        border:solid 1px #000;<br>    }<br>    &lt;/style&gt;<br>    <br>&lt;/head&gt;<br>

&lt;body onload=&quot;init()&quot;&gt;<br>        &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;<br>    &lt;div&gt;<br>        &lt;h2&gt;Qick example: TODO: Dispose all map guide objects, use StringBuilder, etc...&lt;/h2&gt;<br>

        &lt;h3&gt;Showing only Districts/Hydrography&lt;/h3&gt;<br>    &lt;/div&gt;<br>        &lt;div id=&quot;map_mg&quot;&gt;<br>        &lt;/div&gt;<br>    &lt;/form&gt;<br>    <br>    &lt;script type=&quot;text/javascript&quot;&gt;<br>

        var addrs = &quot;<a href="http://localhost/">http://localhost/</a>&quot;;<br>        var mg_url = addrs + &quot;mapguide/mapagent/mapagent.fcgi?USERNAME=Anonymous&amp;&quot;;<br>        var metersPerUnit = 111319.4908;  //value returned from mapguide<br>

        var inPerUnit = OpenLayers.INCHES_PER_UNIT.m * metersPerUnit;<br>        OpenLayers.INCHES_PER_UNIT[&quot;dd&quot;] = inPerUnit;<br>        OpenLayers.INCHES_PER_UNIT[&quot;degrees&quot;] = inPerUnit;<br>        OpenLayers.DOTS_PER_INCH = 96;<br>

        var _map = null;<br>        <br>        function init() {<br>            var extent = new OpenLayers.Bounds(-87.865114442365922, 43.665065564837931, -87.595394059497067, 43.823852564430069);<br>            var mapOptions = {<br>

                maxExtent: extent,<br>                maxResolution: &#39;auto&#39;<br>            };<br>            _map = new OpenLayers.Map(&#39;map_mg&#39;, mapOptions);<br><br>            var options = {<br>                isBaseLayer: true,<br>

                buffer: 1,<br>                useOverlay: false,<br>                useAsyncOverlay: false,<br>                singleTile: true<br>            };<br>            var params = {};<br>            params.mapName = &#39;&lt;%= GetMapName() %&gt;&#39;;<br>

            params.session = &#39;&lt;%= GetMapSession() %&gt;&#39;;<br>            params.hideLayers = &#39;&lt;%= GetHidelayers() %&gt;&#39;;<br>            params.showLayers = &#39;&lt;%= GetShowlayers() %&gt;&#39;;<br>

<br>            mg_layer = new OpenLayers.Layer.MapGuide(&quot;MapGuide Sheboygan map&quot;, mg_url, params, options);<br>            _map.addLayer(mg_layer);<br><br>            _map.addControl(new OpenLayers.Control.MousePosition());<br>

            _map.zoomToMaxExtent();<br><br>        }<br>    &lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br><br><span style="font-family: arial,helvetica,sans-serif;">Pietro Ianniello</span><br></span><br>