Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to protect ASP.NET Web API 2

I need to implement ASP.NET Web API 2 i.e.

[RoutePrefix("orders")] 
public class OrdersController : ApiController 
{ 
    [Route("{id}")] 
    public Order Get(int id) { } 
    [Route("{id}/approve")] 
    public Order Approve(int id) { } 
} 

I am wondering how it can be protected?

Can we use ASP.NET Identity for that, for instance?

Any clue?

like image 889
Friend Avatar asked Mar 21 '23 03:03

Friend


1 Answers

You could add the [Authorize] attribute to the class and then send the basic authentication information via the header.

like image 80
Mike Perrenoud Avatar answered Apr 06 '23 18:04

Mike Perrenoud