Reputation: 1061
I currently have a lot of Web APIs that are being used by various applications. All of the APIs are using ASP.NET Web API 2 with 4.6 .NET framework. I want to be able to keep track of all the different applications that are using a specific API.
Example:
Lets say I have the following API:
And I have the following applications that call the Employees API
/intranet/employee/add
/intranet/timeoff.aspx
The Employee Management System calls the Employees API using HttpClient in C# code.
The Time Off Request Form calls the Employees API using an ajax call in JavaScript.
I want to keep a log of all the applications that are using a Web API and preferably what action they are calling. What is the best way to achieve this?
Is there a way to get the Callers URI?
From the Web API is it possible to know that /intranet/timeoff.aspx
is calling the the add employee action on the Employee API
Upvotes: 0
Views: 373
Reputation: 778
If you have control of the applications that call your API, then Michael_B offers some good suggestions. If not then you may need to consider some referring information like IP address - see How to get IpAddress and UserAgent in ASP.NET Web API get methods. However, even then that value may not be the client IP but something in between it and your API.
Nevertheless, since you're using Web API, you might consider running all of the requests through a DelegatingHandler first, write the caller info, etc. to a log from there, then let the request continue to the proper controller. See http://arcware.net/logging-web-api-requests/
Upvotes: 1
Reputation: 3818
I believe you have a few options.
Add a header value to identify the application to each request from the applications.
Add a claim identifying the application to a security token (assuming you are securing the requests).
Add a query parameter for the requesting application to each request.
Upvotes: 1