asp.net - Adding a Key Check to all attempts to access any functions in a WebService -


i building web service api provide remote access data management system.

there various functions in api , require access key.

i wrapping insides of functions this:

function getsomething(api_key)     if integratedapis.grant_api_access(api_key)         /// stuff     else         return "api key not provided or incorrect"     end  end function 

obviously integratedapis.grant_api_access(api_key) function returns boolean output , checks user's key in database

this works, problem it's bit of maintenance pain. how can automatically wrap around calls webservice?

is possible via global.asax file return error on application_beginrequest example?

look aspect oriented programming (aop) frameworks .net. these frameworks intercept calls , run them through function relies heavily on reflection.

for example:

// original function call want routed through aop. [keycheck] public void originalfunctioncall() {      ... }  // aop function accepts functions decorated [keycheck]. // runs logic before function, runs function, runs logic after. public void intercept() {     // before original function.     keycheck();      // original function     functioncall();      // logic after original function.     cleanup(); } 

some of frameworks let put annotation on calls want routed through aop framework. when i've used approach, have logic want performed before call executed, call executed, logic want performed after original call.

some .net aop frameworks:

last note: careful performance. of frameworks - since use reflection heavily - can slow down code.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -