Search code examples
c#asp.netwcfiiswcf-data-services

Enable Windows Authentication to AJAX Enabled WCF service in Firefox not working


My website has Windows Authentication and Anonymous Authentication enabled and the database connection also uses windows authentication (based on user login).

I called AJAX-Enabled WCF Service and it is authenticated anonymously.

Everything works fine on IE. But when I opened this with Firefox, is throwing an exception:

Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.

enter image description here

Web.config

    <authentication mode="Windows">
        <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>
    <identity impersonate="true" />
    <authorization>
        <deny users="?" />
    </authorization>
    .....
    .....
 <system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <!--<behavior name="metadataBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
    </behavior>-->
            <!-- Step 2. Add a new behavior below.-->
            <behavior name="metadataBehavior">
                <serviceMetadata  httpGetEnabled="true" httpsGetEnabled="false"/>
                <!-- Step 3. Add a <serviceDebug> element -->
                <serviceDebug  includeExceptionDetailInFaults="true" />
                <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
                <serviceAuthorization/>
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior name="Mycompany.SGACostReduction.EditInitiativesAspNetAjaxBehavior">
                <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
                <webHttp helpEnabled="true"/>
                <enableWebScript />
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false"  />
    <standardEndpoints>
        <webHttpEndpoint>
            <standardEndpoint automaticFormatSelectionEnabled="false"
                              helpEnabled="true"
                              defaultOutgoingResponseFormat="Json"
                              name=""/>
        </webHttpEndpoint>
    </standardEndpoints>
    <services>
        <service name="Mycompany.SGACostReduction.EditInitiatives" behaviorConfiguration="metadataBehavior">
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:57771/EditInitiatives.svc" />
                </baseAddresses>
            </host>
            <endpoint address="" behaviorConfiguration="Mycompany.CostReduction.EditInitiativesAspNetAjaxBehavior" binding="webHttpBinding" bindingConfiguration="webBinding" contract="Alixpartners.SGACostReduction.EditInitiatives"  >
                <identity>
                    <dns value="localhost"/>
                </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>
    <bindings>
        <webHttpBinding>
            <binding name="webBinding">
                <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
              <security mode="TransportCredentialOnly">
                    <transport clientCredentialType="Windows" proxyCredentialType="Windows" />
                </security>
            </binding>
        </webHttpBinding>
    </bindings>
</system.serviceModel>

Solution

  • I think this page can help you

    Whenever you try to call a cross domain WCF Service by javascript or jquery, it behaves differently with different browsers. When you want to perform "POST" or "GET" request on cross domain wcf service or normal service using jquery/javascript or ajax, the browser actually sends an "OPTIONS" verb call to your wcf service that is not mention in your wcf method attribute

    http://www.dotnet-tricks.com/Tutorial/wcf/X8QN260412-Calling-Cross-Domain-WCF-Service-using-Jquery.html