Wednesday, March 7, 2012

IIS Basic authentication problem - 401 Unauthorized error

Hello all,
I have users attempting to view reports (created in Reporting Services 2000)
over the web and they're receiving a "401 - Unauthorized" error due to
invalid credentials. Here is the VB.NET code that's being used to
authenticate the user:
Dim strURL as String = "http://mydomain.mywebsite.com/ReportServer?MyFolder/MyReport?arg1=1&arg2=2&rs:Command=Render&rs:Format=PDF"
Dim ReportWebRequest As HttpWebRequest = CType(WebRequest.Create(strReportURL), HttpWebRequest)
ReportWebRequest.Timeout = 1000000
ReportWebRequest.MaximumAutomaticRedirections = 50
ReportWebRequest.Headers.Add("Authorization", "Basic " +
Convert.ToBase64String(Encoding.ASCII.GetBytes("userid:password")))
ReportWebRequest.PreAuthenticate = True
Dim ReportWebResponse As HttpWebResponse = CType(ReportWebRequest.GetResponse(), HttpWebResponse)
We would prefer not to turn on anonymous access. We are running IIS vers.6
on a Win 2003 Server. Any ideas?
Thanks in advance,
BruceBruce,
Try replacing the following lines of code...
ReportWebRequest.Headers.Add("Authorization", "Basic " +
Convert.ToBase64String(Encoding.ASCII.GetBytes("userid:password")))
ReportWebRequest.PreAuthenticate = True
...with these lines:
Dim cCache = New CredentialCache
cCache.Add(New Uri(strReportURL), "Basic", New NetworkCredential("userid",
"password", "domain"))
ReportWebRequest.Credentials = cCache
Hope this helps,
Steve
"Bruce A" wrote:
> Hello all,
> I have users attempting to view reports (created in Reporting Services 2000)
> over the web and they're receiving a "401 - Unauthorized" error due to
> invalid credentials. Here is the VB.NET code that's being used to
> authenticate the user:
> Dim strURL as String => "http://mydomain.mywebsite.com/ReportServer?MyFolder/MyReport?arg1=1&arg2=2&rs:Command=Render&rs:Format=PDF"
> Dim ReportWebRequest As HttpWebRequest => CType(WebRequest.Create(strReportURL), HttpWebRequest)
> ReportWebRequest.Timeout = 1000000
> ReportWebRequest.MaximumAutomaticRedirections = 50
> ReportWebRequest.Headers.Add("Authorization", "Basic " +
> Convert.ToBase64String(Encoding.ASCII.GetBytes("userid:password")))
> ReportWebRequest.PreAuthenticate = True
> Dim ReportWebResponse As HttpWebResponse => CType(ReportWebRequest.GetResponse(), HttpWebResponse)
> We would prefer not to turn on anonymous access. We are running IIS vers.6
> on a Win 2003 Server. Any ideas?
> Thanks in advance,
> Bruce

No comments:

Post a Comment