Has anyone successfully used the System.Net.HTTPWebRequest with Active Directory authentication in a DotNetNuke website? I have looked around and found several references to HTTPWebRequest and Active Directory authentication, but none seem to have the special sauce. I have tried uncountable variations of the attributes/methods, without success.
The development environment I am working in is a Windows 2003 Server that acts as a backup PDC and runs IIS 6.0. The website is running DotNetNuke 4.9.4 with Active Directory authentication (also tried it in DNN 5.1.4) and is working great for login. However, one of the modules does a HTTPWebRequest to process files and it is faling with a 401 Unauthorized error.
The most basic of code I have tried:
Dim webReq As HttpWebRequest = DirectCast(WebRequest.Create(sURL), HttpWebRequest) webReq.Timeout = 30000 Dim credential As New NetworkCredential(sUserName, sPassword) Dim credentialCache As New CredentialCache() credentialCache.Add(New Uri(sURL), "NTLM", credential) webReq.Credentials = credentialCache webReq.KeepAlive = True webReq.Accept = "/"
I have tried adding PreAuthenticate.
I have also tried registry key modifications, including this one:
Changes to NTLM authentication for HTTPWebRequest in Version 3.5 SP1
All without success. Each time I get the dreaded 401:
The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse()
I have also created a simple aspx page with the following int he code behind: Dim requestUrlString As String = "http://adtestsite/somepage.aspx" Dim webReq As HttpWebRequest = DirectCast(WebRequest.Create(requestUrlString), HttpWebRequest) Dim nc As New NetworkCredential("UserName", "Password", "OurDomainName")
Dim webResponse As System.Net.HttpWebResponse = DirectCast(webReq.GetResponse, HttpWebResponse)
If webResponse.StatusCode = HttpStatusCode.OK Then
Response.Write("Yes!")
Else
Response.Write("NO!")
End If
I get a "NO!" everytime with the 401 error.
I am beating my head against the wall on this one. If anyone has the recipe for the secret sauce, PLEASE let me know!