Nexus23
Nexus23

Reputation: 6373

Response.Redirect to remote pdf url in 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) from 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?

Upvotes: 1

Views: 4839

Answers (4)

Frazell Thomas
Frazell Thomas

Reputation: 6111

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.

Response.Redirect works by sending the browser an HTTP 302 so the target can be on the same server or another server.

Upvotes: 1

walther
walther

Reputation: 13600

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:// in this case.

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.

Upvotes: 0

Erwin
Erwin

Reputation: 4817

You can use Response.Redirect like this:

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

Upvotes: 1

Kapil Khandelwal
Kapil Khandelwal

Reputation: 16144

Try this:

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

Upvotes: 0

Related Questions