Initial setup for a new ASP.NET MVC site in IIS7

Background Over the years, I have spent far too many hours running the same set of commands against ASP.NET and ASP.NET MVC sites to bring them up to what I consider a starting point. Most of the time, I have to refresh myself about how to do at least one of them. This is a list of those commands in a central location for myself and anyone else to use. As with any good instructions, there is no guarantee you won’t completely destroy your server, site, or soul using these commands. I can only say they worked for me once. Remove unnecessary HTTP headers Server X-Powered-By X-AspNet-Version X-AspNetMvc-Version Adding dynamic content compression (e.g., GZIP) GZIP for JSON and JSONP content types (e.g., “application/json”) Complete appcmd command-line list Remove unnecessary HTTP headers By default, IIS and ASP.NET give you a few headers in each and every HTTP response sent out. Server: Microsoft-IIS/7.5 (or 7.0, or whatever IIS version you have) X-Powered-By: ASP.NET X-AspNet-Version: 4.0.303319 (or 2.0.50727, or 1.1.4322, or whatever version you have) X-AspNetMvc-Version: 3.0 (or 2.0, or 1.0, or whatever version you have) People will rant and rave about removing these headers for security and whether that helps. I am… Continue reading

From jsFiddle to GitHub to AppHarbor to

Update I finally put together an app listing on StackApps. If you like and you have a StackApps account, I’d love for your vote on the StackGeography app page. Background My latest project at my full-time job with Sierra Trading Post is their Mashery-managed API. It currently includes most everything you would expect from a retail API: departments, brands, products, search, and reviews. I would like it to include a few things that are less typical but fun to work with from a data aggregation standpoint. One example: recent order locations. While it may not see a lot of outside use, it would be quite nice for our internal observation; it would go great on the handful of large screens around the company with site statistics continually updating on them. In order to put together a proof-of-concept that I could even do this, I wanted to make a mapping demo using someone else’s API. Since I am responsible for the Sierra Trading Post API, I try to research other APIs to learn from their successes and pain points. One such API that has provided a lot of [positive] learning is the Stack Exchange API. It just so happened that… Continue reading

Adapting Visual Studio code styling differences for open source project contribution

Background Today, while incorporating Lee Dumond’s MVC Route/URL Generation Unit Tester into a project, I found a desire to contribute some code I thought would make the package easier to use. Unfortunately, the project code formatting looks nothing like my preferred conventions (some form of 1TBS, I guess). Until Visual Studio offers a way to distribute code style settings to source control consumers easily, I needed a different option. While preparing demos for a mobile web development talk for the Cheyenne Computer Professionals group, I stumbled on Mike Minutillo’s tip for running a “demo” instance of Visual Studio where I could sandbox my presentation settings optimized for an elderly VGA projector. This sparked an workaround idea for dealing with multiple formatting settings of various projects I may work on. Rather than force my conventions on the project (generally not acceptable) or give up on my own style (generally not acceptable), I decided to try using a “demo” instance of Visual Studio with that projects styling conventions set. Right-click where I want the shortcut. Specify a path to Visual Studio 2010 using the /RootSuffix option. On 64-bit Windows, %programfiles(x86)%\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe” /RootSuffix YourStylingNameHere On 32-bit Windows, %programfiles%\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe”… Continue reading

Getting dynamic ExpandoObject to serialize to JSON as expected

Serializing ExpandoObjects I am currently creating a JSON API for a handful of upcoming Sierra Trading Post projects. When I found myself generating JSON for a stripped-down representation of a number of domain classes, all wrapped with some metadata, I turned to dynamic and things have been going quite well. Unfortunately, there was a hurdle to getting the JSON to look the way I wanted. If you start playing around with serializing ExpandoObject to JSON, you will probably start finding a number of options. The easiest solution to find is the one that comes with .NET, JavaScriptSerializer under System.Web.Script.Serialization. It will happily serialize an ExpandoObject for you, but it probably won’t look the way you expect. Your searches will probably vary, but I found Newtonsoft’s JSON.NET, which handled ExpandoObject right out of the NuGet box. Then I stumbled on ServiceStack.Text (also “NuGettable”). While it does even weirder things than the .NET serializer with ExpandoObjects, it supposedly does them very fast. Test code dynamic test = new ExpandoObject(); test.x = “xvalue”; test.y = DateTime.Now; BCL JavaScriptSerializer (using System.Web.Script.Serialization;) JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); string jsonOfTest = javaScriptSerializer.Serialize(test); // [{“Key”:”x”,”Value”:”xvalue”},{“Key”:”y”,”Value”:”\/Date(1314108923000)\/”}] Not quite what I was looking for but it makes sense if… Continue reading

Subtleties with using Url.RouteUrl to get fully-qualified URLs

At some point I missed the Url.RouteUrl overload that took a protocol and returned an absolute URL based on the current context. It is quite handy when you are sending URLs out into the world (e.g., RSS feed link). I ended up using the less-handy overload that took an explicit host (same as the current, in this case) and passing it in. When someone pointed out the simpler overload, I did the obvious and deleted the host from the call. That didn’t quite work. For those looking for a way to get a fully-qualified URL through the route system, the less-than-obvious answer is to call the overload for Url.RouteUrl that gets a URL with a different protocol (Url.RouteUrl(string, object, string)), passing in Request.Url.Scheme for the current protocol. Url.RouteUrl(“Default”, new { action = “Index”, controller = “Department”, id = 1 }, Request.Url.Scheme); // Say you want to send someone to a different subdomain in your app while using the same routes. There’s an overload for that: Url.RouteUrl(string, RouteValueDictionary, string, string). Combined with the above example, here’s how these all play out if you are currently handling a request and your route table includes the fallback default ({controller}/{action}/{id}). Url.RouteUrl(“Default”, new… Continue reading