I have a website which use Active Directory Federation Services to authenticate the user. I want to access a URL for the site using HttpWebRequest class in code. But when I try that, I get a 401 error. After some research I found that it uses NTLM authentication. I tried this solution. But I see that the response I get is a HTML page with some hidden fields and it has a javascript to submit the page on load. The action URL will be that of my domain. I tried to submit the HTML text as a form manually but again I get the same response. Not so sure how I can access the page. Anyone has an Idea?
Asked
Active
Viewed 582 times
1 Answers
0
I've been dealing with just such an issue over the past few days. After trying many things I eventually resorted to the following method:
- Create a System.Net.CookieContainer object and pass it to the CookieContainer of every httpwebrequest.
- Manually parse the form elements and pass them off as the RequestStream to the form's target. This must be done as POST and not GET on the httpwebrequest.
- For any consecutive request, make sure you attach the same CookieContainer. There is where your authenticated ADFS cookies are stored. Without them you'll just hit an endless loop.
Regards