In the case of an ASP.NET Web API 2 service or even a standalone MVC system, because of the way I handle errors and such, I prefer to use JsonResult
functions in my controllers:
public class BaseController : Controller
{
// This controller is where functionality common to all
// controllers (such as error reporting goes. It's also good for avoiding
// code repetition as in the case of the next function
public JsonResult CreateResponse(object Data)
{
// send a JsonResult with the specified data
return Json(Data, JsonRequestBehavior.AllowGet);
}
}
public class UserController : BaseController
{
public JsonResult Create(CreateUserViewModel Model)
{
try
{
var User = new User
{
Username = Model.Username,
EmailAddress = Model.EmailAddress,
Password = Hashing.CreateHash(Model.Password)
};
db.Users.Add(User);
db.SaveChanges();
return CreateResponse(true);
}
catch (Exception ex)
{
return CreateResponse(ex.Message);
}
}
}
In what situations would I want to AllowGet or DenyGet on the JsonRequestBehavior?
What are the implications or concerns of either course?