views:

54

answers:

2

We have some code that uses a third party component to generate a PDF from a URL that we pass it (the URL being a page within our application). In the code, we instantiate the PDF generator and it creates the PDF in an asynchronous fashion.

The problem I have is that if the URL that we pass it has a problem, there is no indication of this from the PDF generator, we just get a PDF created that contains a 404 error page, or our custom error page.

I need some way, within my controller, to first call this URL (which is another view) and check that it does not error out, prior to calling the PDF generation. Can anybody point me in the direction of how I might go about doing this?

+1  A: 

Do an Http Request first against the URL. I use WatIn for all my URL interactions, which I find sufficiently hides the details allowing me to validate a page prior to use. However for this you really just need HttpRequest

Russell Steen
+1  A: 

You can to a HttpRequest to the URL first, then check the HttpWebResponse.StatusCode If you get a 404 or a 500 (etc) then you have a problem.

Radu094
That seems to make a lot of sense, thanks very much.
Paddy