Making WebRequest to SharePoint using Windows Authentication in Mixed Mode Authentication

Mixed mode authentication is when both Form Based Authentication (FBA) and Windows Authentication are enabled on the SharePoint site. I was writing some code to download a file from SharePoint in this scenario. The code needs to authenticate using Windows Authentication.

I found my solution at this post: http://buyevich.blogspot.com/2011/03/accessing-mixed-authentication-web-app.html. Essentially we need to add the header “X-FORMS_BASED_AUTH_ACCEPTED” to the request and set its value to “f”. I tested this on the WebClient class and it works!

As a side note, I found this post to make the request using FBA, i.e. with user name and password: http://dhondiyals.wordpress.com/2010/07/05/file-download-from-sharepoint-document-library-in-forms-based-authentication-scenario/. Haven’t tested so don’t know if it works – but it looks promising.

Update: And if your site is using SSL, you may run into the error below in DEV/TEST:

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

In which case, try setting the ServerCertificateValidationCallback as described in this post: http://stackoverflow.com/questions/703272/could-not-establish-trust-relationship-for-ssl-tls-secure-channel-soap (it worked for me!).

Advertisements

About Bernado

Based in Australia, I am a freelance SharePoint and Dynamics CRM developer. I love developing innovative solutions that address business and everyday problems. Feel free to contact me if you think I can help you with your SharePoint or CRM implementation.
This entry was posted in Claim Authentication, Form Based Authentication, Mixed Mode Authentication. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s