Respuesta. Redirigir a URL remota de pdf en asp.net

I have couple of asp.net link buttons, can't change them to asp.net hyperlinks. I want to open a pdf file when buttons are clicked while pdf files are located on a different server (example http://www.targetserver.com/sample.pdf) de http://www.sourceserver.com where link buttons are. Want to open pdfs in the same window. Can I use Response.Redirect somehow passing in pdf url which opens pdf in the same window?

preguntado el 28 de agosto de 12 a las 14:08

Have you at least tried it or what exactly is the question?? -

I have tried, Response.Redirect("targetserver.com/sample.pdf") but it navigates like this sourceserver.com/www.targetserver.com/sample.pdf -

See my answer, should provide a solution for you. -

4 Respuestas

Yes, a response redirect will work just fine as long as you pass the fully qualified URL.

Response.Redirect("http://www.site.com/target.pdf");

Should redirect the browser to the PDF file.

Respuesta.Redirección works by sending the browser an HTTP 302 so the target can be on the same server or another server.

Respondido 28 ago 12, 16:08

Thanks Frazell, can you please let me know how to pass the fully qualified url, I am struggling making it fully qualified. - Nexus23

Added a sample and link to documentation to explain Response.Redirect. - Frazell Thomas

You can use Response.Redirect like this:

Response.Redirect("http://www.targetserver.com/sample.pdf");

Respondido 28 ago 12, 15:08

Prueba esto:

protected void LinkButton1_Click(object sender, EventArgs e)
{
   Response.Redirect("http://www.targetserver.com/sample.pdf");
}

Respondido 28 ago 12, 15:08

I have tried, Response.Redirect("targetserver.com/sample.pdf";) but it navigates like this sourceserver.com/www.targetserver.com/sample.pdf

Of course, because if you don't specify the protocol, it assumes you're referring to some file located on the server. You need to append http:// en este caso.

Furthermore, the action "what happens" depends on user's client. If the client doesn't have Adobe Reader installed or has set his browser to save files instead of opening them, it obviously won't open. If you want to be sure that the file gets opened in the browser, you need to implement some pdf reader on your website.

Respondido 28 ago 12, 15:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.