Open external PDF file in asp.net MVC 2

I know how to open an internal pdf file:

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

The question is how to open a PDF file from another / external website, for example. http://example.com/mypdffile.pdf

+3
source share
2 answers

You really don't need a controller action for this. You could simply:

<a href="http://www.blabla.com/mypdffile.pdf">Open mypdffile.pdf</a>

Of course, if you want to hide this address from the user, you can use WebClient to get it on the server:

public ActionResult GetPDF() 
{ 
    using (var client = new WebClient())
    {
        var buffer = client.DownloadData("http://www.blabla.com/mypdffile.pdf");
        return File(buffer, "application/pdf", "mypdffile.pdf");
    }
}

And in your opinion:

<%= Html.ActionLink("Download PDF", "GetPDF") %>
+5
source

, , . WebClient HttpRequest/HttpResponse,

0

Source: https://habr.com/ru/post/1789965/


All Articles