What's the IIS virtual filepath to my Resources directory?

493 Views Asked by At

I'm having trouble finding the correct path to pass into a the src attribute of an <img> tag, that references an image stored in a C# project's Resources folder. (Build Action: Content. Copy To Output Directory: Copy if Newer)

I have a RESTFUL service that, based on the id in the URL, will generate an invoice PDF. To generate the PDF, the service uses Handlebars.Net to generate HTML for the invoice, and Select.HtmlToPdf to convert that HTML into the PDF.

When I step though my code, the project that uses Select.HtmlToPdf to generate the PDF seems to have a current working directory of C:\Program Files (x86)\IIS. (I found that by setting a quick watch of: System.IO.Directory.GetCurrentDirectory().

The resulting PDF does not show the image I want to display. I've had this work as expected in a console application, so I suspect the issue is the path I'm passing into the src argument in the HTML is incorrect for this project.

When I build, I can see the image file in \bin\Resources\. What is the relative path to that image resource that I should be passing into the src attribute of that <img> tag?

Update 05/16

Rather than generate a PDF, I had my controller return HTML to the browser to see if it would display correctly. It did. In this case, the src attribute of the <img> tag was \Resources\image.png. It looks like, when the browser goes to fetch the image by calling <baseurl>\Resources\image.png, the controller translates that path correctly.

So my problem is Select.HtmlToPdf isn't making a web request to fetch the image, it's taking that src argument as the local path to the image file it needs to load, so I need to find a way to access the Resources folder of my bin directory via the virtual directories that the IIS environment sets up.

0

There are 0 best solutions below