簡體   English   中英

在asp.net MVC 2中打開外部PDF文件

[英]Open external PDF file in asp.net MVC 2

我知道如何打開內部pdf文件:

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

問題是,如何從其他/外部網站打開PDF文件,例如http://example.com/mypdffile.pdf

你真的不需要控制器動作來做到這一點。 你可以簡單地說:

<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") %>

無論如何,您將需要本地進行任何處理,因此,您可以將其下載到本地文件夾然后顯示它。 使用WebClient或HttpRequest / HttpResponse對象進行下載

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM