Thursday, July 1, 2010

Bing Ajax Control over HTTPS or HTTP Secure

So I have not updated in awhile, why you ask? Because I have been neck deep for months on 5 large projects and one of them has been “Geo Mapping”.

 

So recently I was integrating the project into the main portal site, which runs under HTTPS. We are using the Bing API  and all I had to do was flip the URL to the Bing control from HTTP to HTTPS.

Woops, wrong there. Not entirely anyhow everything worked except that the map tiles were being pulled from HTTP still. So after hunting about for a day I found an undocumented parameter, well no documentation that I could locate.

So here are the two ways to add the Bing Ajax control to your page in HTTP or HTTPS:

HTTP:

<script src=”http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3” type="text/javascript"></script>

HTTPS:

<script src=”https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3&s=1” type="text/javascript"></script>

Now on the HTTPS version notice I changed the URL to start with HTTPS, this is what pulls from the secure site over at the good Bing folks. Also notice I added the “s” parameter and set it to 1, default is 0, this tells the Bing API to get the image tiles for the map from HTTPS.

Why? you ask.

Well it seems that the API determines what protocol to use for JavaScript and other parts from the document.location.protocol, however when it comes to the map tiles it looks to a global setting that is set based on the parameter being passed.

 

Well we all make mistakes but at least I found a solution. And I hope that anyone else that runs into it will find this post. Enjoy!