views:

196

answers:

3

I have a report that I currently allow the user to choose an output option (HTML or PDF) when they are supplying the report parameters (date range, filters, etc.).

I want to change the report such that it always does HTML and puts a link on the rendered HTML page so the user can grab the PDF if they want it.

How do I modify my IIS6/IIS7 configuration, user permissions, etc. to allow my site to write the PDF to the filesystem? Any C# code would be appreciated.

I plan on creating PDFs with random filenames and adding a process to cleanup old PDFs so I don't have a disk space issue. This is a lightly used web application so I'm not worried about having lots of old PDF files hanging around.

A: 

All you should need to do is be sure that the user ID that the web site is running under (or the user that's logged in if your site runs that way) has write permission to the directory you are creating the PDFs in.

Moose
+4  A: 

In IIS 6 Manager, go to Application Pools and get the properties of the Application Pool your web site is running under (if you're not sure, it's on the web site Properties dialog > Home Directory tab). Go to the identity tab and see what user account that app pool is running under.

Then go to the target folder you want to write the PDF to, right-click and go to Properties > Security > Add and add "write" for the account listed for the app pool.

Rex M
+1 for more detail than mine, but if there's an <identity impersonate="true" > entry in web.config, or if IIS is doing authentication, that will take precedence.
Moose
A: 

You should take a look at the System.Security.Permissions namespace and the FileIOPermission class in .NET so that you can make sure your file permissions are set properly when trying to write your files.

I use it in much the same way that you need it (writing PDF files to the server before serving them back up to the user).

TheTXI