diff --git a/Rotativa.Demo/Controllers/HomeController.cs b/Rotativa.Demo/Controllers/HomeController.cs
index 39f121f..a6fd892 100644
--- a/Rotativa.Demo/Controllers/HomeController.cs
+++ b/Rotativa.Demo/Controllers/HomeController.cs
@@ -160,6 +160,21 @@ public ActionResult ErrorTest()
return new ActionAsPdf("SomethingBad") { FileName = "Test.pdf" };
}
+ public ActionResult HttpStatus500Test()
+ {
+ return new UrlAsPdf("https://httpstat.us/500") { FileName = "Test.pdf" };
+
+ }
+ public ActionResult HttpStatus404Test()
+ {
+ return new UrlAsPdf("https://httpstat.us/404") { FileName = "Test.pdf" };
+ }
+ public ActionResult HttpStatus200Test()
+ {
+ return new UrlAsPdf("https://httpstat.us/200") { FileName = "Test.pdf" };
+
+ }
+
public ActionResult SomethingBad()
{
return Redirect("http://thisdoesntexists");
diff --git a/Rotativa.Demo/Views/Home/Index.cshtml b/Rotativa.Demo/Views/Home/Index.cshtml
index 8000b1f..ecd4d6d 100644
--- a/Rotativa.Demo/Views/Home/Index.cshtml
+++ b/Rotativa.Demo/Views/Home/Index.cshtml
@@ -4,30 +4,33 @@
@ViewBag.Message
-
- - @Html.ActionLink("Home", "Index", new {name = "Giorgio"})
- - @Html.ActionLink("Test", "Test", "Home")
- - @Html.ActionLink("Test Image", "TestImage", "Home")
- - @Html.ActionLink("Test Image Png", "TestImagePng", "Home")
- - @Html.ActionLink("Test URL", "TestUrl", "Home")
- - @Html.ActionLink("Test External URL", "TestExternalUrl", "Home")
- - @Html.ActionLink("Test View", "TestView", "Home")
- - @Html.ActionLink("Test View Image", "TestViewImage", "Home")
- - @Html.ActionLink("Test Save on Server", "TestSaveOnServer", new { fileName = "test.pdf"})
- - @Html.ActionLink("Logged In Test", "AuthorizedTest", "Home")
- - @Html.ActionLink("Logged In Test Image", "AuthorizedTestImage", "Home")
- - @Html.ActionLink("Route Test", "RouteTest", "Home")
- - @Html.ActionLink("Test ViewAsPdf with a model", "TestViewWithModel")
- - @Html.ActionLink("Test ViewAsImage with a model", "TestImageViewWithModel")
- - @Html.ActionLink("Test PartialViewAsPdf with a model", "TestPartialViewWithModel")
- - @Html.ActionLink("Test PartialViewAsImage with a model", "TestImagePartialViewWithModel")
- - @Html.ActionLink("Error Test", "ErrorTest", "Home")
- - @Html.ActionLink("Binary Test", "BinaryTest", "Home")
- - @Html.ActionLink("Ajax Test", "Index", "AjaxTests")
- - @Html.ActionLink("Ajax Image Test", "IndexImage", "AjaxTests")
- - @Html.ActionLink("External CSS Test", "Index", "CssTests")
- - @Html.ActionLink("External CSS Test Image", "IndexImage", "CssTests")
-
+
+ - @Html.ActionLink("Home", "Index", new { name = "Giorgio" })
+ - @Html.ActionLink("Test", "Test", "Home")
+ - @Html.ActionLink("Test Image", "TestImage", "Home")
+ - @Html.ActionLink("Test Image Png", "TestImagePng", "Home")
+ - @Html.ActionLink("Test URL", "TestUrl", "Home")
+ - @Html.ActionLink("Test External URL", "TestExternalUrl", "Home")
+ - @Html.ActionLink("Test View", "TestView", "Home")
+ - @Html.ActionLink("Test View Image", "TestViewImage", "Home")
+ - @Html.ActionLink("Test Save on Server", "TestSaveOnServer", new { fileName = "test.pdf" })
+ - @Html.ActionLink("Logged In Test", "AuthorizedTest", "Home")
+ - @Html.ActionLink("Logged In Test Image", "AuthorizedTestImage", "Home")
+ - @Html.ActionLink("Route Test", "RouteTest", "Home")
+ - @Html.ActionLink("Test ViewAsPdf with a model", "TestViewWithModel")
+ - @Html.ActionLink("Test ViewAsImage with a model", "TestImageViewWithModel")
+ - @Html.ActionLink("Test PartialViewAsPdf with a model", "TestPartialViewWithModel")
+ - @Html.ActionLink("Test PartialViewAsImage with a model", "TestImagePartialViewWithModel")
+ - @Html.ActionLink("Error Test", "ErrorTest", "Home")
+ - @Html.ActionLink("Binary Test", "BinaryTest", "Home")
+ - @Html.ActionLink("Ajax Test", "Index", "AjaxTests")
+ - @Html.ActionLink("Ajax Image Test", "IndexImage", "AjaxTests")
+ - @Html.ActionLink("External CSS Test", "Index", "CssTests")
+ - @Html.ActionLink("External CSS Test Image", "IndexImage", "CssTests")
+ - @Html.ActionLink("HttpStatus 500 Test", "HttpStatus500Test", "Home")
+ - @Html.ActionLink("HttpStatus 404 Test", "HttpStatus404Test", "Home")
+ - @Html.ActionLink("HttpStatus 200 Test", "HttpStatus200Test", "Home")
+
diff --git a/Rotativa.Tests/RotativaTests.cs b/Rotativa.Tests/RotativaTests.cs
index 3442a36..d54194b 100644
--- a/Rotativa.Tests/RotativaTests.cs
+++ b/Rotativa.Tests/RotativaTests.cs
@@ -360,5 +360,40 @@ public void Can_print_image_from_page_with_external_css_file()
image.RawFormat.Should().Be.EqualTo(ImageFormat.Jpeg);
}
}
+
+ [Test]
+ public void HttpError_statuses_does_not_generate_pdf_file()
+ {
+ var testLink = selenium.FindElement(By.LinkText("HttpStatus 200 Test"));
+ var pdfHref = testLink.GetAttribute("href");
+
+ var content = "200 OK";
+ using (var wc = new WebClient())
+ {
+ var pdfResult = wc.DownloadData(new Uri(pdfHref));
+ var pdfTester = new PdfTester();
+ pdfTester.LoadPdf(pdfResult);
+ pdfTester.PdfIsValid.Should().Be.True();
+ pdfTester.PdfContains(content).Should().Be.True();
+ }
+
+ testLink = selenium.FindElement(By.LinkText("HttpStatus 404 Test"));
+ pdfHref = testLink.GetAttribute("href");
+
+
+ using (var wc = new WebClient())
+ {
+ Assert.Throws(typeof(WebException), () => wc.DownloadData(new Uri(pdfHref)));
+ }
+
+ testLink = selenium.FindElement(By.LinkText("HttpStatus 500 Test"));
+ pdfHref = testLink.GetAttribute("href");
+
+
+ using (var wc = new WebClient())
+ {
+ Assert.Throws(typeof(WebException), () => wc.DownloadData(new Uri(pdfHref)));
+ }
+ }
}
}
diff --git a/Rotativa/WkhtmlDriver.cs b/Rotativa/WkhtmlDriver.cs
index a733e91..799a454 100644
--- a/Rotativa/WkhtmlDriver.cs
+++ b/Rotativa/WkhtmlDriver.cs
@@ -70,7 +70,7 @@ protected static byte[] Convert(string wkhtmlPath, string switches, string html,
string error = proc.StandardError.ReadToEnd();
- if (ms.Length == 0)
+ if (ms.Length == 0 || !string.IsNullOrEmpty(error) || proc.ExitCode > 0)
{
throw new Exception(error);
}