我知道如何打开内部 pdf 文件:
public ActionResult GetPDF( string filename )
{
return File( filename, "application/pdf", Server.HtmlEncode( filename ) );
}
问题是,如何从其他/外部网站打开 PDF 文件,例如http://example.com/mypdffile.pdf
最佳答案
你真的不需要 Controller Action 来做到这一点。你可以简单地:
<a href="http://www.blabla.com/mypdffile.pdf">Open mypdffile.pdf</a>
当然,如果你想对用户隐藏这个地址,你可以使用 WebClient 在服务器上获取它:
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");
}
}
在您看来:
<%= Html.ActionLink("Download PDF", "GetPDF") %>
关于c# - 在asp.net MVC 2中打开外部PDF文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4897197/