Tips and Tricks in a world of Mix

Posts tagged ‘Windows Authentication’

Changing Wcf from Anonymous to Windows Authentication – server and client basicHttpBinding sample

This solution has been developed for Intranet and doesn’t take in concert security issues of Internet

I got some client using the Windows Auth but the wcf could read the
ServiceSecurityContext.Current.PrimaryIdentity

So  I had to turn the Windows Auth for wcf also.

The Wcf couldn’t show the services through the new Authentication until I didn’t change the mexHttpBinding to the basicHttpBinding

Server Side :

<bindings>
<basicHttpBinding>
<binding name="MyBasicHttp" allowCookies="true"
maxReceivedMessageSize="2147483647"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
openTimeout="10:00"
>
<readerQuotas maxDepth="2147483647" 
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>

<!--<security mode="TransportCredentialOnly">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>-->
</security>
</binding>
</basicHttpBinding>
</bindings>
.
.
.
<services>
<service name="Egged.Tnua.Wcf.ServiceImpl.EventService" 
behaviorConfiguration="DefaultBehavior">
<endpoint address="" 
binding="basicHttpBinding" bindingConfiguration="MyBasicHttp"
contract="My.Wcf.IServiceImpl.IEventService" />
<!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />-->
<endpoint address="mex" binding="basicHttpBinding" contract="IMetadataExchange" bindingConfiguration="MyBasicHttp" />
</service>

 

Client Side

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IMyService"
                  openTimeout="00:10:00"
                   sendTimeout="00:10:00"
                  allowCookies="true"
                  bypassProxyOnLocal="false"
                  maxBufferPoolSize="200000000"
                  maxReceivedMessageSize="200000000">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
</basicHttpBinding>
    </bindings>
    <client>
 
      <endpoint address="http://localhost/MyWcfPublishedName/MyServiceEndpoint.svc"
             binding="basicHttpBinding"
             bindingConfiguration="BasicHttpBinding_IMyService"
             contract="MyService.IMyService"
            name="BasicHttpBinding_IMyService" />
</client>   </system.serviceModel>

Very important – in client in order that the binding would be activated on the endpoint you ought to add its name 

to bindingConfiguration and Name

It’s getting very importnat when there is a lot of data going through and the default binding just isn’t enough.

 

Advertisements

Mvc with Windows Authentication results – /login.aspx?ReturnUrl=%2f – solution

When first published on server the MVC  has been Anonymous. then changed to windows Authentication caused

The resource cannot be found.

The url has been the standart need one but – /login.aspx?ReturnUrl=%2fEgged.Tnua.TimeTable%2fHome

The solution is :

adding the following lines to the AppSettings section of my web.config file in appSettings:

<add key="autoFormsAuthentication" value="false" />
<add key="enableSimpleMembership" value="false"/>

Weirdly enough – solved the problem!

Found it here

http://stackoverflow.com/questions/8205368/request-redirect-to-account-loginreturnurl-2f-since-mvc-3-install-on-server

Tag Cloud

%d bloggers like this: