Skip to content

Instantly share code, notes, and snippets.

@RhysC
Created December 8, 2014 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RhysC/651bb54a3c0040085d11 to your computer and use it in GitHub Desktop.
Save RhysC/651bb54a3c0040085d11 to your computer and use it in GitHub Desktop.
Show file as web page, not an automatic download | MVC Asp.net filter
public class InlineFileAttribute : ActionFilterAttribute
{
private const string ContentDisposition = "Content-Disposition";
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
var headers = filterContext.HttpContext.Response.Headers;
if (!string.IsNullOrWhiteSpace(headers[ContentDisposition]))
headers[ContentDisposition] = headers[ContentDisposition].Replace("attachment", "inline");
base.OnResultExecuted(filterContext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment