I have an action who displays a PDF in a new browser tab.
public ActionResult Print()
{
var cd = new ContentDisposition
{
Adding to kodandarami's answer,
When you're passing a PDF file back from ASP.NET MVC, the page title is set to the last url part of the route config used to get to your controller.
Knowing this, you can dynamically name the title by setting up a parameter as part of the route config for your controller eg:
routes.MapRoute(
"Print",
"print/{pdfName}",
new { controller = "Print", action = "Index", pdfName = UrlParameter.Optional }
);
Then MVC will use this value instead as it considers it a separate page.
Use it in the url as "/print/this-is-my-pdf-title" not '/print?pdfName=this-is-my-pdf-title".
As a querystring parameter, MVC will just fall back to calling the PDF 'print'.
Note: As mentioned in this related question,
IIS has more strict rules about forbidden characters when the text is before the query string '?' character. You are not allowed <,>,*,%,&,:,\
(See MS Reference)
Any of these characters, even when encoded will give you a 'Path is potentially dangerous' 400 error.
Make sure to remove/replace these forbidden characters.
.