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?
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
Post a Comment