ASP.Net Controller API nuggets

Write Directly to Response Stream

Stack-o basically covers this already but kinda danced around how minimal the code can really be for the basic scenario…

  • in my experience, the ContentType wasn’t even necessary but it feels like good practice
  • here i’m using a database layer represented by my own custom Proc class… which is a bundle of convenient methods wrapped around SqlCommand … in this case, it’s firing SqlCommand.ExecuteReader() and writing the results directly to the response via Newtonsoft.Json StreamWriters… i honestly haven’t done a real profile on this call stack but it feels like a nice straight shot from sql streaming through web tier transform to client
  • another nifty nugget in play here is the usage of C# Dynamic to catch arbitrary JS objects posted from the ajax client, and that Dynamic is then inherently castable to a Dictionary