About the author

Steven HarmanSteven Harman is a passionate developer who believes that writing great software isn't just a job, its a craft.

ASP.NET MVP

For recent posts and more about me, scroll to the bottom.

Subscribe

  • Subscribe to my feed. via RSS
  • Subscribe via email via email

Jobs

Badges

  • Subtext Project
  • Support Subtext
  • HiddenNetwork.com Banner

Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application

A couple of days ago I was using ASP.NET WebForms and the new ReportViewer control to put together a quick demo for rendering SQL Server Reporting Services (SSRS) reports right in your web application.

If you're not familiar with the ReportViewer control, Thom Robbins put together a great screencast to introduce the ReportViewer control.

How I used the control

I was running the control in remote mode - meaning it pulls the reports down from a fully managed SSRS installation, and then renders them directly in the web browser - all from within my application. I was also using Windows Authentication because the client required it.

Anyhow, everything worked beautifully on my local dev box VM, but when I pushed it out to a staging server it was a no-go.

The request failed with HTTP status 401: Unauthorized.

Time to do some Googling! As luck would have it - or maybe not - this seems to be a pretty common issue so there are a lot of blogs, mailing lists, forums, etc... talking about it. 

I quickly realized this was an authentication issue and because my web app and Reporting Services were both using Windows Authentication there seemed to be a disconnect in the authentication mechanism.

Some possible solutions?

I happened across a blog post by Russell Christopher where he explains in great detail how to make the ReportViewer impersonate the logged in user so that when it hits SSRS it will pass along the user's credentials - as opposed to passing along the YOURMACHINENAME\ASPNET credentials that ASP.NET usually runs with.

In the end I didn't end up using his code because I didn't need to dynamically swap the identity, I just needed to be sure to pass along credentials for a user that had rights to SSRS. To do that all I needed to do was edit my web.config and add the following element under the system.web section:

<identity impersonate="true" />

After making the change I tried to view the report again and... same error, doh!

RegEditAfter another hour (or so) of searching and trying various fixes I finally came across an article by Greg Van Mullem that explains how to configure SSRS to run in a non-Default web site. The key piece of information I culled from Greg's guide was all the way at the bottom in Step 7.3 - Disable loopback checking.

I realize the error message I was getting isn't listed under the Symptoms in the Microsoft KB article but I figured I might as well try it as nothing else was working. So I fired up RegEdit, made my way to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa and, created a new DWORD named DisableLoopbackCheck with a value of 1.

Is it working yet?

After that I tried to view the report once more and... Bingo! I was back in business.

I then proceeded to revert all changes I had made one at a time and retest the report viewer. In the end, the only changes I needed were the two described in this post.

  1. Set your ASP.NET application to impersonate the logged in user
  2. Modify the registry - adding the DisableLoopbackCheck key.

Hopefully you can take a little knowledge away from this post and save yourself a little time and a lot of frustration. Good luck!

What others are saying.

# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar Erikk
Mar 29, 2007
I am having this same problem. Question, on what server did you set the registry setting? On your SQL Report Server or the web server where your application was running?

I have the exact same issue, it works fine on my test machine but when I push the app out to our web server I get the 401 error. I added that registry entry into our SQL Report Server. I reset the machine, but I still get the same error.
# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar Steve Harman
Mar 29, 2007
Ah, good question... I could have been a bit more clear on that point. The registry change was made on the Reporting Services box.

Again, the 401 seems to be a pretty common issue and from the research I've done there are many possible causes - this "Loopback Checking" registry fix is only one.

I'd highly advise you to read the how to configure SSRS to run in a non-Default web site guide I linked to in the post... it does a great job of laying it out step-by-step.

Sorry I couldn't be of more help on this one. Good luck!
# Avoiding the '401 Unauthorized' Error when Using the ReportViewer
Gravatar DotNetKicks.com
Apr 04, 2007
You've been kicked (a good thing) - Trackback from DotNetKicks.com
# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar Stephen
Apr 26, 2007
You just made my day!!!! We were facing the same issue (2 reportservers in NLB configuration) The registry key modification (on both reportservers) solved the problem!
# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar malay majumder
May 08, 2007
want to open the web as to unblock the websites blocked by NETGEAR Firewall
# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar Lori
May 31, 2007
We are having this same issue. Is it possible for you to post some sample code including the important web.config sections?

Thanks.
# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar Steve Harman
May 31, 2007
@Lori: all the sample code that you should need is already included in this post.

As I mentioned near the end of the post (in the Is it working yet? section), I only ended up needing the two changes mentioned in this post. Re-read the Some possible solutions section again for full details, but the gist is I ended up doing the following:

edit my web.config and add the following element under the system.web section:

<identity impersonate="true" />


And then make one change to my registry:

Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa and, created a new DWORD named DisableLoopbackCheck with a value of 1.


If you have more questions, please let me know. Hope this helps!
# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar Troy
Aug 22, 2007
We're getting the same error, but from the KB, I'm under the impression the registry fix doesn't apply to Windows 2003 SP2. Is that correct?
# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar Steven Harman
Aug 22, 2007
@Troy: The staging server that I mentioned in the 4th paragraph was indeed an instance of Windows Server 2003 - though I don't recall what Service Pack level the machine was at.

I'd say to go ahead and give it a try and if it doesn't fix your issue, or screws something else up, just revert the registry change.

Hope this helps!
# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar Brian Chang
Oct 19, 2007
Thank you for this tip! You saved my life :-)
# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar Jeff
Oct 22, 2007
Thank you, thank you, thank you for retracing all of my own frustrated steps until the solution. I had to go a further step with the identity tag and include a userName and password. I think I'll have to fix that for security, but for now, it works. Thanks again.
# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar Nick
Jan 28, 2008
Hi Steven,
I'm still having the error even the code fix and registry fix. the reports are OK in Report Manager. Only got the problem with reportviewer. any more suggestion?
# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar Nick
Jan 29, 2008
I got it. :D after 2 days of headache. :D The problem is i only set the permissions to the website and the virtual directory where my ASPX pages exists, but not to the Report and Report Server virtual directories. So, after setting the permission of these VDs to use with windows authentication, it's working now. Geez! ...
# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar Chris
Feb 18, 2008
Thanks! That fixed our issue as well. Just wish I would have found your page sooner. I won't admit to how much time we wasted on this one.
- Chris
# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar Martin Hinshelwood
Mar 04, 2008
I am afraid that none of this fixed my similar issue :( back to hard sludge of Google...
# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar Jason Hickman
May 01, 2008
You are a ledgend. After 3 days of working on this, 2 days of getting the 401 error i finaly found your page. implemented the reg change and fixed it!
Thank You!
-Jason
# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar Chris Rogers
Jul 09, 2008
Ug. Still no luck. Kerberos is working, I can see that much. The reg fix had no effect. What a crock. My single biggest challenge on my current project has been security on IIS 6.0.

Thanks for the tip, though. One step closer to finding the issue.
# re: Avoiding the '401 Unauthorized' Error when Using the ReportViewer in Your Web Application
Gravatar Chris Rogers
Jul 09, 2008
FOUND IT! Ok, this is a wierd one. I had to add the domain to my trusted sites. I did *.domainname.com, but I'm sure you can just add the servers themselves. In any case, apparently there was a silent authentication going on and since IE thought it was a Internet site, it didn't know to automatically authenicate for me.
Comments have been closed on this topic.