c# - custom authorization and authentication in wcf webhttpbindig -


i create simple wcf service webhttpbinding can see :

    [operationcontract]     [webinvoke(method = "get", uritemplate = "/data/{data}")]     string getdata(string data); 

and implementation :

   public string getdata(string value)         {                  return string.format("you entered: {0}", value);          } 

i want create custom authorization , authentication 2 weeks can't.i googled lot ,but can find authentication wshttpbinding not webhttpbinding .

my recent question describe main problem :

my authorize custom function in wcf doesn't execute .should define in webconfig?

my customauthorizationpolicy.evaluate() method never fires

you can implement serviceauthorizationmanager provide authorization wcf service webhttpbinding.

your code similar this:

public class customauthorizationmanager : serviceauthorizationmanager {     protected override bool checkaccesscore(operationcontext operationcontext)     {         try         {             servicesecuritycontext securitycontext = operationcontext.servicesecuritycontext;             windowsidentity callingidentity = securitycontext.windowsidentity;              windowsprincipal principal = new windowsprincipal(callingidentity);             return principal.isinrole("administrators");         }         catch (exception)         {             return false;         }     } } 

then register custom serviceauthorizationmanager in web.config file:

<servicebehaviors>   <behavior name="servicebehaviour">     <servicemetadata httpsgetenabled="true"/>     <serviceauthorization serviceauthorizationmanagertype="yournamespace.customauthorizationmanager, yourassemblyname"/>   </behavior> </servicebehaviors> 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -