Tuesday, March 24, 2009

ASP.NET MVC - Preventing an Action Method from Being Called Publicly

By default, any action method defined in a controller class can be called via a browser request. To prevent this, simply mark the method with the [NonAction] attribute:

[NonAction] public ActionResult Index(int AreaCode) { return View(); } The result of calling a non-action method will be an HTTP 404 error: "The resource cannot be found."

No comments: