CustomAuthorizationPolicy.Evaluate() method never fires in wcf webhttpbinding

孤街浪徒 提交于 2019-11-30 18:43:22

You might need to set serviceCredentials in your web config file:

<serviceCredentials type="YourString">
     <YourTagsHere>
     </YourTagsHere>
</serviceCredentials>

Here's a link to more information about serviceCredentials: https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/wcf/servicecredentials

You can specify your custom AuthorizationPolicy within the <serviceAuthorization> tags, e.g.:

<serviceAuthorization serviceAuthorizationManagerType=
        "wcfrestauth.RestAuthorizationManager, wcfrestauth">
  <authorizationPolicies>         
    <add policyType="wcfrestauth.AuthorizationPolicy, wcfrestauth"  
  </authorizationPolicies> 
</serviceAuthorization>

In the WCF docs there is a good example for Implementing a Custom Authorization Policy for a WCF service.

Be careful, though, when overriding the CheckAccess method of the abstract AuthorizationManager base class. The method of the base class calls the GetAuthorizationPolicies method internally to retrieve a collection of all IAuthorizationPolicy objects present (see also this blog article).

If you override CheckAcces and do not invoke the method of the parent class, not any Evaluate method of the IAuthorizationPolicy objects will be called.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!