I need to block direct access of action method by web browser. However I want to invoke the actions through ajax call.
The following code does the job for me
public ActionResult DashBoard()
{
if (Request.IsAjaxRequest())
{
return View();
}
else
{
return RedirectToAction("Index");
}
}
However writing if else
block in every action method is hectic thing to do and there must be better way to handle it globally.