Contacts

Link Addresses to Google Maps with JQuery (Part 1)

First, you need JQuery. I'm not going to go into the basics of JQuery, but you should be using it.

Second, We use this to create a global class, usable throughout the website to signify an address, and provide links to Google Maps. The stripHTML function is only required if you wish to markup your addresses for formatting. From then on, you just do a

  1. <span class="address">1600 Amphitheatre Parkway<br />Mountain View, CA 94043

Now for the code:

  1. function stripHTML(oldString) {
  2.    var newString = "";
  3.    var inTag = false;
  4.    for(var i = 0; i < oldString.length; i++) {
  5.         if(oldString.charAt(i) == '<') inTag = true;
  6.         if(oldString.charAt(i) == '>') {
  7.               inTag = false;
  8.               i++;
  9.         }
  10.         if(!inTag) newString += oldString.charAt(i);
  11.          }
  12.    return newString;
  13. }
  14.  
  15.  
  16. /* <span class="address">Address</span> will auto create link to Google Maps */
  17. $(function() {
  18.         $(".address").each(
  19.                 function() {
  20.                         var address = this.innerHTML
  21.                         this.innerHTML = '<a href="http://maps.google.com/maps?q=' + stripHTML(address) + 'class="map">' + address + '</a>';
  22.                 }
  23.         );
  24. });

Keep in mind, we only want to wrap the address inside the tags.

In part 2, we'll use JQuery with Google Maps to allow the user to view the map on the website, or jump off to Google Maps.

Filed under:

XHTML strict compliant Google Map embedding - with JQuery!

Google Maps

 

It seems that every time I go to embed a Google map into a site I'm working on, I forget about Google's IFRAME failure. In this particular case, I wasn't up for running through the API, and I just wanted to embed the map on the page, and have it validate. First, let me say you need to be using JQuery (if you're not, you should be). Second, a document.write is not the solution to your issue, if you're not putting the Javascript code in a separate file. As this code is only run on one page, I'm not going to bother. First, you're going to create your div wherer you'd like your map:


  1. <div id="#map"></div>

Next, you're going to wrap your JQuery calls in script tags, and escape the CDATA tags with:

  1. <script type="text/javascript">
  2. //<![CDATA[
  3. $(document).ready(function() { $("#map").append('<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;amp;source=s_q&amp;amp;hl=en&amp;amp;geocode=&amp;amp;q=Google,+Mountain+View,+CA&amp;amp;sll=39.774769,-72.949219&amp;amp;sspn=56.795811,135.351563&amp;amp;ie=UTF8&amp;amp;ll=37.432477,-122.079906&amp;amp;spn=0.029142,0.06609&amp;amp;z=14&amp;amp;iwloc=A&amp;amp;cid=11972054812773967638&amp;amp;output=embed"></iframe>
  4. <br /><small><a href="http://maps.google.com/maps?f=q&amp;amp;source=embed&amp;amp;hl=en&amp;amp;geocode=&amp;amp;q=Google,+Mountain+View,+CA&amp;amp;sll=39.774769,-72.949219&amp;amp;sspn=56.795811,135.351563&amp;amp;ie=UTF8&amp;amp;ll=37.432477,-122.079906&amp;amp;spn=0.029142,0.06609&amp;amp;z=14&amp;amp;iwloc=A&amp;amp;cid=11972054812773967638" style="color:#0000FF;text-align:left">View Larger Map</a></small>'); });
  5. //]]>
  6. </script>

This will place the map inside your div, AND validate!

Filed under:

McAfee Antivirus with IIS6.0 and ASP.NET Performance

A scenario came up at work when I went to roll the latest project up to production from our QA environment.
 
Our application was the first .NET 2.0 application to be built in this environment. The high-level executives had been pushing for a transition of all development to Java. A few managers had managed to convince the executives to let us take this particular application into .NET 2.0. You can imagine my suprise after 6 months of development, I roll to production and performance was awful. It had never been great in our QA environment, but it always ran at an acceptable pace. It did however seem to run great on our development boxes. I chalked it up to our QA environment not being up to par with our development boxes or our production servers (Mistake #1). After going through and hunting down the worst performing methods using Red-Gate ANTS .NET Profiler, I revamped the code and pushed a new release to a production server not in service yet and performed some load tests. Performance had improved but was still in the red zone.
 
After a long discussion with the server hosting team, I began to question the production environments. I knew they were running VMWare instances, and I thought perhaps that could be degrading performance. But why was it quicker on our QA servers then our production servers? Those too are VMWare instances. Weeks went by where I was on the phone and exchanging emails with the hosting team trying to figure it out. I needed help. I talked with some other members of our development team who had launched a .NET 1.1 application on similar VMWare instances, and they had mentioned running into issues with McAfee Antivirus and the ScriptProxy.dll issue (http://www.kbalertz.com/kb_917848.aspx).
 
A meeting was scheduled in which we would go have a sit down with the server hosting guys and take a look at the configuration of the servers. In the meantime, I gathered some load tests using Microsoft’s Application Center Test application on a Dell desktop machine. Our application performed quite well on that machine, and that wasn’t even server hardware. When I got to the meeting and started poking around on the server, I saw McAfee Antivirus running. One of the server hosting guys said that ScriptProxy.dll wasn’t registered, and that couldn’t be the issue. I urged them to disable McAfee Antivirus for a few minutes just to run some tests, but after a long argument, I finally caved in (Mistake #2).
 
We looked over everything else and it all seemed to be setup just fine. We left four hours later with heavy heads. As we were leaving, the hosting team sent some memory dumps over to Microsoft to take a look. I feared the worst. He’ll find something wrong with my code, I can see it now. We grabbed a quick bite to eat for lunch on the way home at a local deli and tried to imagine every scenario we could, and what we would do next. I got back to the office and went to tell the project manager the bad news…
 
My phone rang mid-sentance and I recognized the number. I interrupted the project manager and answered it. It was one of the guys who had gone to the hosting team with us, who was still in the car on the way back to his office. He said Microsoft had called… McAfee was injecting itself into the worker processes.
 
The hosting guys had disabled McAfee Antivirus on one of the servers. I could not have typed faster if my life depended on it. Response times were immaculate. Sub-second page responses. It was like a dream come true. I could hear him laughing in his car. He was the one who had gone to the executives to convince them to give us a chance to do it in .NET. We had done it. Moral of the story, watch what those Antivirus applications do. In this particular case, it had almost destroyed two seperate applications. The one done by other members of my team, and the one I had done. I still don’t know if McAfee has released a patch for this issue. If they do, I’ll post a link here.
 

Filed under:

Managing two websites with seperate master page files and development environments.

I came across a situation the other day where I was developing two websites that used the same base code, but differentiated by masterpage files and a few settings in the web.config to make calls to web services and databases. Our initial development had been hurried, so everytime we rolled to production, we changed the masterpage file, and the settings by commenting out the sections of the web.config. When I finally got sick of doing this, I started writing code to handle this. First, I uncommented the lines in the web.config, and added prefixes to the key names.
  1. <appsettings>
  2.     <!– Production Settings –>
  3.     <add key="prodSetting1" value="prodValue1"></add>
  4.     <add key="prodSetting2" value="prodValue2"></add>
  5.     <add key="prodSetting3" value="prodValue3"></add>
  6.  
  7.     <!– QA Settings –>
  8.     <add key="qaSetting1" value="qaValue1"></add>
  9.     <add key="qaSetting2" value="qaValue2"></add>
  10.     <add key="qaSetting3" value="qaValue3"></add>
  11.  
  12.     <!– Site 1 Settings –>
  13.     <add key="site1MasterPageFile" value="~/site1.master"></add>
  14.     <add key="site1Theme" value="site1"></add>
  15.  
  16.     <!– Site 2 Settings –>
  17.     <add key="site2MasterPageFile" value="~/site2.master"></add>
  18.     <add key="site2Theme" value="site2"></add>
  19. </appsettings>
After that, we create a new class in the App_Code folder, which inherits System.Web.UI.Page
  1. Public Class MyCustomPage
  2.     Inherits System.Web.UI.Page
  3.     Public Setting1 As String
  4.     Public Setting2 As String
  5.     Public Setting3 As String
  6.  
  7.     Private Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
  8.         If Request.ServerVariables("HTTP_HOST").StartsWith("qa.") Then
  9.             Setting1 = System.Configuration.ConfigurationManager.AppSettings("qaSetting1")
  10.             Setting2 = System.Configuration.ConfigurationManager.AppSettings("qaSetting2")
  11.             Setting3 = System.Configuration.ConfigurationManager.AppSettings("qaSetting2")
  12.         Else
  13.             Setting1 = System.Configuration.ConfigurationManager.AppSettings("prodSetting1")
  14.             Setting2 = System.Configuration.ConfigurationManager.AppSettings("prodSetting2")
  15.             Setting3 = System.Configuration.ConfigurationManager.AppSettings("prodSetting2")
  16.         End If
  17.  
  18.         If Request.ServerVariables("HTTP_HOST").Contains("ryanmarrs.com") Then
  19.             Page.Theme = System.Configuration.ConfigurationManager.AppSettings("site1Theme")
  20.             Page.MasterPageFile = System.Configuration.ConfigurationManager.AppSettings("site1MasterPageFile")
  21.         Else
  22.             Page.Theme = System.Configuration.ConfigurationManager.AppSettings("site2Theme")
  23.             Page.MasterPageFile = System.Configuration.ConfigurationManager.AppSettings("site2MasterPageFile")
  24.         End If
  25.     End Sub
  26. End Class
After this, we change the inherits on our web pages to the following:
  1. Partial Public Class _Default
  2.     Inherits MyCustomPage
  3.  
  4.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  5.         me.Label1.text = Setting1
  6.         me.Label2.text = Setting2
  7.         me.Label3.text = Setting3
  8.     End Sub
  9. End Class
We’re done. You can also create inheritance for things like UserControls or MasterPage files if you need those settings inside them Keep in mind, usercontrols and master page files don’t get a theme or a master page file.
Filed under: