Skip to content

Instantly share code, notes, and snippets.

@danlash
Created February 15, 2011 19:24
Show Gist options
  • Save danlash/828060 to your computer and use it in GitHub Desktop.
Save danlash/828060 to your computer and use it in GitHub Desktop.
A proposal to allow JsonResult from GET in ASP.NET MVC except for arrays
class Program
{
static void Main(string[] args)
{
var model = new {AccountNumber = 123};
var arr = new[] { model };
Console.WriteLine(CurrentJson(model));
Console.WriteLine(CurrentJson(arr));
Console.WriteLine(CurrentJson(arr,true));
Console.WriteLine(SafeJson(model));
Console.WriteLine(SafeJson(arr));
Console.ReadKey();
}
static string CurrentJson(object model)
{
return model is IEnumerable ? "get allowed" : "get not allowed";
}
static string CurrentJson(object model, bool allowGet)
{
return "manually allow get";
}
static string SafeJson(object model)
{
return "get allowed";
}
static string SafeJson(IEnumerable model)
{
return "get not allowed, force manual method";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment