Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Reporting Services Development
 Error 403 Forbidden

Author  Topic 

FCazabon
Starting Member

7 Posts

Posted - 2011-01-14 : 13:28:59
Hi,

I'm writing an ASP.NET C# application that makes use of Reporting Services to generate PDFs from the data. I use a command like this to call the report:

http://localhost/ReportServer/Pages/Report.aspx?%2fSIAS+Reports%2fReceipt&rs:Command=Render&rs:Format=PDF&rc:Parameters=false&ReceiptNumber=0000000039

Which works fine if I put it directly in the browser (although the first time I try it I need to login), but when calling it in my application I get a 403 Forbidden error returned. I guess this means there is some security issue. If I look in the Event Viewer I see this:

Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 01/14/2011 8:00:45 AM
Event time (UTC): 01/14/2011 12:00:45 PM
Event ID: fd216790eada4779be60461c14263d75
Event sequence: 14
Event occurrence: 1
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/1/ROOT/SIAS-1-129394800055232727
Trust level: Full
Application Virtual Path: /SIAS
Application Path: C:\SIASMachine name: NEWIMIASDB
Process information:
Process ID: 4316
Process name: w3wp.exe
Account name: IIS APPPOOL\DefaultAppPool
Exception information:
Exception type: WebException
Exception message: The remote server returned an error: (403) Forbidden.
Request information:
Request URL: http://localhost/SIAS/ReceiptEdit.aspx
Request path: /SIAS/ReceiptEdit.aspx
User host address: ::1
User:
Is authenticated: False
Authentication Type:
Thread account name: IIS APPPOOL\DefaultAppPool
Thread information:
Thread ID: 5
Thread account name: IIS APPPOOL\DefaultAppPool
Is impersonating: False
Stack trace: at System.Net.HttpWebRequest.GetResponse()
at SamaanSystems.IAS.Web.ReceiptEdit.btnSave_Click(Object sender, EventArgs e) in C:\Development\Mere Mortals .NET Framework 2008\SamaanSystems\IAS.Web\ReceiptEdit.aspx.cs:line 420
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Custom event details:

So that looks like the DefaultAppPool does not have access to something.

If I change the credentials on the request to the administrator login it works.

I don't want to hard code a username and password in my code, so what can I do?

__
Frank

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-01-14 : 17:48:58
Use IIS to configure permissions to folders that are required for access.



Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page

FCazabon
Starting Member

7 Posts

Posted - 2011-01-17 : 06:51:44
Thanks for the response, but I do not see any SSRS folders when running IIS. I have no idea what folders are the ones causing trouble here.

__
Frank
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2011-01-17 : 07:36:39
Hm, I don't know the answer but I'd try to give the user that's running the asp.net application pool access to the ReportServer database and also IIS access to http://localhost/ReportServer. Been a long time since I worked with IIS...

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

FCazabon
Starting Member

7 Posts

Posted - 2011-01-17 : 07:58:41
Thanks, but I cannot find localhost\ReportServer in the IIS administration applet. Something changed from SSRS 2005 or 2008 to SSRS 2008 R2 so that IIS no longer displays the ReportManager and ReportServer sites. So any ideas how I can work out what folder and what user (this could be any amount of users) to give access to that folder?

__
Frank
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2011-01-17 : 08:18:08
..if I could only get my http://localhost/Reports to work... :(

How about clicking the "Show details"-link...does it give you any permission options? ->



- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2011-01-17 : 09:37:08
For some obscure reason my reportserver just started working, so I was able to browse the site which makes it a little easier. If you click the "Site settings" in the top right corner and then the Security tab you should be able to add the user with proper permissions (I hope...).

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

FCazabon
Starting Member

7 Posts

Posted - 2011-01-17 : 11:09:35
OK, thanks, I'm getting to the Site Settings, now how do I add the DefaultAppPool user? I get the option add New Role Assignment and try to add that name, but then get an error that DefaultAppPool is not recognized.

__
Frank
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2011-01-18 : 03:05:24
Ok, I really don't have any more advice except I found an article that seemingly has a slightly different approach to the problem: http://www.codeproject.com/KB/reporting-services/PDFUsingSQLRepServices.aspx

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

FCazabon
Starting Member

7 Posts

Posted - 2011-01-18 : 06:54:27
Thanks, that article is very close to what I have been trying. Setting the default credentials is what doesn't work. If I change that to using a a hard coded password it works, but that's not what I want to do.

Thanks for your help

__
Frank
Go to Top of Page

ramonal
Starting Member

2 Posts

Posted - 2012-01-17 : 08:39:39
Hi, I have exactly the same problem and it makes me crazy because I can't find the solution!! Did you solve the problem? Could you share it and help me, please?

I'm desperate with this problem.

Thanks in advance!

Ramón.
Go to Top of Page

FCazabon
Starting Member

7 Posts

Posted - 2012-01-17 : 13:29:47
Sorry Ramón, it's been so long since I worked on this that I can't remember if I even got a solution. I'll see if I can look at the system again and see what I did. If you don't hear from me by tomorrow, post here again to remind me.

__
Frank
Go to Top of Page

ramonal
Starting Member

2 Posts

Posted - 2012-01-18 : 06:42:41
Thanks a lot FCabazon,

I'm looking for a solution for a week and it's making me crazy.

If you could help me I'd appreciate it greatly.

Thanks again
Go to Top of Page

FCazabon
Starting Member

7 Posts

Posted - 2012-01-19 : 07:08:34
Hi again,

I looked back at my code and what I do is store a username and password in a settings file and use that to connect.

Here's my C# code (hope it helps):


string URL = oAppSettings.ReportServerURL + "?/SIAS Reports/Receipt&rs:Command=Render&rs:Format=PDF&rc:Parameters=false&ReceiptNumber=" + this.oReceipt.Entity.ReceiptNumber;

System.Net.HttpWebRequest Req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(URL);

Req.Credentials = new NetworkCredential(oAppSettings.ReportServerUser, oAppSettings.ReportServerPassword);
Req.Method = "GET";

//Specify the path for saving.
string path = HttpContext.Current.Server.MapPath(@"~/Receipts/") + this.oReceipt.Entity.ReceiptNumber + @".pdf";

System.Net.WebResponse objResponse = Req.GetResponse();
System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create);
System.IO.Stream stream = objResponse.GetResponseStream();
byte[] buf = new byte[1024];
int len = stream.Read(buf, 0, 1024);
while (len > 0)
{
fs.Write(buf, 0, len);
len = stream.Read(buf, 0, 1024);
}
stream.Close();
fs.Close();


__
Frank
Go to Top of Page
   

- Advertisement -