InterviewSolution
| 1. |
Consider you want to restrict the users from requesting the method or Action directly in the URL of the browser. How it can be done? |
|
Answer» TWO of the methods to ACHIEVE the result for this scenario are: Option 1: The ChildActionMethod will permit you for restricting access to ACTION methods that you don’t want users to directly REQUEST in the URL of the browser. [ChildActionOnly] public ActionResult demoPiper() { return View(); }Now, the demoPiper() action method cannot be directly requested by the user through the URL of the browser. Option 2: In ASP.NET MVC, each controller’s method is accessed through a URL, and in case you don’t want an action CREATED by you to be accessible through URL then you need to protect your action method with the help of the NonAction attribute provided by the MVC. [NonAction]public ActionResult demoPiper() { return "demoPiper.com"; }After the demoPiper() method is declared as NonAction, if you try to access the method or action through URL, then HTTP 404 Not Found error will be returned. |
|