April 2017
Intermediate to advanced
564 pages
24h 7m
English
Here is the example of annotating attributes on EmployeeController:
[Authorize] [Route("api/[controller]")] public class EmployeeController : Controller { [HttpGet] public List<Employee> Get() { return GetEmployees(); } [HttpPost] public bool Create(Employee employee) { return CreateEmployee(employee); } [HttpDelete] public bool Delete(int id) { return DeleteEmployee(id); } [HttpPut] public bool Update(Employee employee) { return UpdateEmployee(employee); } } }
Annotating the authorize attribute on the Controller level will protect all the methods defined within it.
Alternatively, we can also apply the authorize attribute on the action level, as follows. In the following example, we have added ...
Read now
Unlock full access