Posts

Intro to using the Windows Debugger

Image
Windows Debugger can be downloaded as part of the Windows SDK . I would install both the 32 and 64bit versions. I used it in the past when diagnosing why a website was performing poorly during peak periods. Users would hit the website url, wait for 30+ seconds and then the site would appear quickly. Even the home page which did nothing (i.e. no db hits), was slow to appear. I got a memory dump from the server and using the analysis approach below could see that all available IIS worker threads were in use and all were busy rendering. The server was starved of threads and user requests were ending up in a queue waiting to be processed. I tweaked the IIS settings and added more worker threads. The problem went away. Thanks Windows Debugger! How do you to get a memory dump? 1. Open a command prompt 2. Get the list of worker process ids: %systemroot%\system32\inetsrv\APPCMD list wps This is a useful page describing how AppCmd works: http://www.iis.net/learn/get-started/get...

MVC HTTP Headers for CDN caching

Image
On a recent project I added upgraded our systems to use a Content Delivery Network (CDN). The project supplied content to users and we wanted to offload the 'heavy-lifting' of the content supply away from our PROD server onto a more robust delivery network. The mobile clients would request the content from the CDN. If the CDN hadn't cached the content yet, it would grab it from our PROD server, cache it, and respond back to the clients. For this caching to work, though, some HTTP Header magic was required. Which headers should you watch out for? Cache control should be public For the CDN to cache the content on behalf of your origin server, set the Cache-control=public Expires Date To stop the CDN regularly requested the same static content from your PROD server, set the Expires-Date setting to be in the far future (e.g. > 1 year)  Vary  Watch out for the 'Vary' header. MVC3 had initially defaulted to adding the "vary=*" http head...

Splitting a polygon using SQL Server Spatial queries

Image
A recent project involved drawing regions on a map of a country using the Bing Maps Silverlight control . The user could zoom in to a suburb and draw a region (polygon) around an area on the map. Another feature, and hence the purpose of this blog post, involved enabling a user to draw a line through a region (polygon) and split the region in two: how was that splitting done? Note: you will probably need some database experience and ideally some Bing/Google Maps experience for this to make sense A quick intro to SQL Server Spatial queries SQL Server 2008 introduced support for geo-spatial data . The two new spatial data types are: Geometry: supports flat data surfaces. The following will create a polygon and a line and you can see that our resulting rectangle and line are straight: DECLARE @Geometry GEOMETRY = 'POLYGON((10 10, 40 10, 40 40, 10 40, 10 10))' DECLARE @Linestring GEOMETRY = 'LINESTRING(5 5, 50 50)' SELECT @Geometry SELECT @Linestr...

Using Get & Post from Silverlight to a RESTful service

A recent project I was working on needed a lot of data to be passed quickly between a Silverlight client and a .Net server. The approach taken, instead of using a relatively-heavy XML SOAP implementation, was to go with a lightweight JSON REST web service. Information on the web is moderately clear on how this works, but I found the POST part of the picture to be virtually non-existent. As I would be passing in more data than some browsers support through the querystring, I didn't have any other option: I had to figure it out. Thus, if you need that info, read on... GET The following is a sample web service with one GET method:     [ServiceContract]     [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]     public class MyTestService     {         [OperationContract(Name = "MyTestMethod")]  ...

Single Installer for multiple environments

Image
With quite a few contracts I have been working on over the years I have ended up helping out with the build process for ASP.Net websites. Many existing enterprise build processes I have encountered tend to involve making a custom build of the codebase for UAT and then once UAT is passed making another build for PROD. This process brings in a significant risk of a developer on a team checking in changes AFTER UAT was build and thus ending up with untested code in PROD. This risk is unnecessary. The following is an approach I have used at a number of enterprises for creating a single .msi installer which can be run in a DEV environment (if it exists), then copied into a UAT environment for user testing before finally being copied and run in PROD. The single installer gets built once but can handle the different server/database configurations of the different environments and can install the correct .config files in each environment. The methodology is as follows: Within Visual Studio...