I want to do the same thing as in this link:
http://www.codeproject.com/KB/WCF/Custom_Authorization_WCF.aspx
But without using configuration files. Can anyone show me how?
Edit: I want to implement both AuthorizationPolicy and the CustomValidator.
Are you referring about how to add the AuthorizationPolicy through code? Untested, but I believe something like this should work:
ServiceHost host = ...;
var col = new ReadOnlyCollection<IAuthorizationPolicy>(new IAuthorizationPolicy[] { new MyPolicy() });
ServiceAuthorizationBehavior sa = host.Description.Behaviors.Find<ServiceAuthorizationBehavior>();
if ( sa == null ) {
sa = new ServiceAuthorizationBehavior();
host.Description.Behaviors.Add(sa);
}
sa.ExternalAuthorizationPolicies = col;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With