asp.net - WCF REST/JSON Service UserNamePasswordValidator -


i'm trying use basic authentication wcf rest/json service.

therefore i've create class derives "usernamepasswordvalidator" , added web.config. in iis basic authentication enabled.

unfortunately class never called. when call rest method in browser dialog entering username , password shown nothing happens after that.

here web.config

<?xml version="1.0" encoding="utf-8"?> <configuration>   <appsettings>     <add key="aspnet:usetaskfriendlysynchronizationcontext"           value="true" />   </appsettings>   <system.web>     <compilation debug="true" targetframework="4.5" />     <httpruntime targetframework="4.5" />     <identity impersonate="true" />   </system.web>   <system.servicemodel>     <services>       <service name="mytimemvc.webservice.mytimerestservice"                behaviorconfiguration="returnfaults">         <endpoint behaviorconfiguration="restfulbehavior"                   binding="webhttpbinding"                    bindingconfiguration="webbinding"                   contract="mytimemvc.webservice.imytimerestservice" />       </service>     </services>     <bindings>       <webhttpbinding>         <binding name="webbinding">           <security mode="transportcredentialonly">             <transport clientcredentialtype="basic" />           </security>         </binding>       </webhttpbinding>     </bindings>     <behaviors>       <endpointbehaviors>         <behavior name="restfulbehavior">           <webhttp />         </behavior>       </endpointbehaviors>       <servicebehaviors>         <behavior name="returnfaults">           <servicedebug includeexceptiondetailinfaults="true" />           <servicemetadata httpgetenabled="true" />           <datacontractserializer maxitemsinobjectgraph="2147483647" />           <servicecredentials>             <!--<servicecertificate findvalue="mywebsite"                                     storelocation="localmachine"                                     storename="my"                                     x509findtype="findbysubjectname" />-->             <usernameauthentication usernamepasswordvalidationmode="custom"                                     customusernamepasswordvalidatortype="mytimeservicedemoa.wcfextension.customusernamevalidator,testwcfserviceauth" />           </servicecredentials>         </behavior>       </servicebehaviors>     </behaviors>   </system.servicemodel>   <system.webserver>     <modules runallmanagedmodulesforallrequests="true" />     <!--         browse web app root directory during debugging, set value below true.         set false before deployment avoid disclosing web app folder information.       -->     <directorybrowse enabled="true" />     <validation validateintegratedmodeconfiguration="false" />   </system.webserver> </configuration> 

here customusernamevalidator.cs

namespace mytimeservicedemoa.wcfextension {  public class customusernamevalidator : system.identitymodel.selectors.usernamepasswordvalidator {      public override void validate(string username, string password)     {          if (null == username || null == password)         {             throw new argumentnullexception("you must provide both username , password access service");         }          if (!(username == "user1" && password == "test") && !(username == "user2" && password == "test"))         {              throw new faultexception("unknown username or incorrect password");          }     } } } 

update: after 2 days of trying give because don't see may have done wrong. seems stuff not working me... investigated lot , need change authentication of webapplication in iis "basic" , add custom "customusernamevalidator" in web.config not working! please correct me if i'm wrong.

my solution:

  1. use "anonymous authentication" in iis
  2. use "serviceauthorizationmanager" , check http-headers in "checkaccesscore"

cheers, stefan


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -