From a3bf36c63aea69174be1377831762a4fe889e2d7 Mon Sep 17 00:00:00 2001 From: akonyer Date: Tue, 24 Feb 2015 17:39:06 -0700 Subject: [PATCH] Add content-disposition flag --- Rotativa/AsPdfResultBase.cs | 9 ++++++++- Rotativa/Options/Enums.cs | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Rotativa/AsPdfResultBase.cs b/Rotativa/AsPdfResultBase.cs index 3a88664..a9e6d6c 100644 --- a/Rotativa/AsPdfResultBase.cs +++ b/Rotativa/AsPdfResultBase.cs @@ -37,6 +37,11 @@ public string CookieName set { FormsAuthenticationCookieName = value; } } + /// + /// This will be send to the browser as the content disposition telling it how to return the document + /// + public ContentDisposition ContentDisposition { get; set; } + /// /// Custom name of authentication cookie used by forms authentication. /// @@ -277,8 +282,10 @@ protected HttpResponseBase PrepareResponse(HttpResponseBase response) { response.ContentType = ContentType; + string contentDisposition = ContentDisposition == ContentDisposition.Inline ? "inline" : "attachment"; + if (!String.IsNullOrEmpty(FileName)) - response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", SanitizeFileName(FileName))); + response.AddHeader("Content-Disposition", string.Format("{0}; filename=\"{1}\"", contentDisposition, SanitizeFileName(FileName))); response.AddHeader("Content-Type", ContentType); diff --git a/Rotativa/Options/Enums.cs b/Rotativa/Options/Enums.cs index 4299c72..705b244 100644 --- a/Rotativa/Options/Enums.cs +++ b/Rotativa/Options/Enums.cs @@ -165,4 +165,10 @@ public enum Orientation Landscape, Portrait } + + public enum ContentDisposition + { + Attachment, + Inline + } }