I am building a Web Service API to provide remote access data from a management system.
There are various functions in the API and all require an access key.
I am currently wrapping the insides of all functions like this:
Function GETSOMETHING(api_key)
If IntegratedApis.Grant_Api_Access(api_key) Then
/// DO STUFF
Else
Return "API KEY not provided or incorrect"
End
End Function
Obviously my IntegratedApis.Grant_Api_Access(api_key)
function returns a boolean output and checks the user's key
in the database
This works, but the problem is it's a bit of a maintenance pain. How can I automatically wrap this around ALL calls to the webservice?
Is it possible via the global.asax
file to return the error on Application_BeginRequest
for example?