From 0bf783db4d36b4a7496b1f7456656ebe0aeb1f60 Mon Sep 17 00:00:00 2001 From: mdemmers Date: Tue, 14 Oct 2014 09:25:16 +0200 Subject: [PATCH] Update ViewAsPdf.cs --- Rotativa/ViewAsPdf.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Rotativa/ViewAsPdf.cs b/Rotativa/ViewAsPdf.cs index e191bcf..c35b7bf 100644 --- a/Rotativa/ViewAsPdf.cs +++ b/Rotativa/ViewAsPdf.cs @@ -101,7 +101,9 @@ protected override byte[] CallTheDriver(ControllerContext context) StringBuilder html = sw.GetStringBuilder(); // replace href and src attributes with full URLs - string baseUrl = string.Format("{0}://{1}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Authority); + // string baseUrl = string.Format("{0}://{1}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Authority); + // Use the original HttpContext from the passed in ControllerContext. In some situations the HttpContext is null. An async (awaited) DI injected service with Ninject lost his HttpContext. + string baseUrl = string.Format("{0}://{1}", context.HttpContext.Request.Url.Scheme, context.HttpContext.Request.Url.Authority); html.Replace(" href=\"/", string.Format(" href=\"{0}/", baseUrl)); html.Replace(" src=\"/", string.Format(" src=\"{0}/", baseUrl)); @@ -110,4 +112,4 @@ protected override byte[] CallTheDriver(ControllerContext context) } } } -} \ No newline at end of file +}