views:

67

answers:

3

I want to have my pdf files sent this way to my users :

public ActionResult GetPDF( string filename )
{
    return File( filename, "application/pdf", Server.HtmlEncode( filename ) );
}

But I don't know how to create a route that will catch all the different pdf file in my site?

Thanks a lot for the help!

A: 

Does this help?

http://weblogs.asp.net/rajbk/archive/2009/11/25/rendering-an-rdlc-directly-to-the-response-stream-in-asp-net-mvc.aspx

Raj Kaimal
No, it does not even talk about routing.
VinnyG
A: 

I found a way to do what I was trying to do just read this link : http://forums.iis.net/t/1162518.aspx or this one http://dotnetslackers.com/articles/aspnet/Range-Specific-Requests-in-ASP-NET.aspx

It's not by routing but with a Handler in IIS.

If someone has a better solution, please, let me know :)

EDIT :

It's realy not working great, you can take a look here : http://www.ville.st-augustin.qc.ca/carte-interactive click on "carte de zonage" tab and then on any adobe icon and it's not working as it should be... any help appreciated!

VinnyG
A: 

Try this..

string FilePath = MapPath("your.pdf");
Response.ContentType = "Application/pdf";
Response.AppendHeader( "content-disposition", "attachment; filename=" + FilePath);
Response.WriteFile(FilePath);
Response.End();

EDIT:

Oups just saw it's MVC...

Try to append the header anyway before returning...

Mike Gleason jr Couturier
It's working, I simply added the content-disposition header in my PDFDownloadHandler like this public override string GetRequestedFileMimeType(HttpContext context) { context.Response.AppendHeader("content-disposition", "attachment; filename=" + context.Request.PhysicalPath); return "application/pdf"; }
VinnyG
nice thanks for sharing
Mike Gleason jr Couturier