Page redirection after loading PDF

I have an aspx page (say 1.aspx), from where I first upload the pdf file, and then I want to redirect to the page with thanks. The code looks like this:

protected void btnSubmit_Click(object sender, EventArgs e) { string pathId = string.Empty; if (Page.IsValid) { try { pathId = hidId.Value; DownloadPDF(pathId); Response.Redirect("Thanks.aspx"); } catch (Exception ex) { throw ex; } } } protected void DownloadPDF(string pathId) { if (!(string.IsNullOrEmpty(pathId))) { try { Response.ContentType = "application/pdf"; Response.AppendHeader("Content-Disposition", "attachment; filename=" + pathId + ".pdf"); string path = ConfigurationManager.AppSettings["Pdf_Path"].ToString() + "\\" + pathId.Trim() + ".pdf"; Response.TransmitFile(path); } catch (Exception ex) { throw ex; } finally { HttpContext.Current.ApplicationInstance.CompleteRequest(); } } } 

The problem is that the file save dialog fits correctly, and I can also upload the file, but it does not redirect to the Thanks.aspx page.

How to resolve this?

+4
source share
5 answers

It was easier for me to put the PDF download page in an iframe. In this way, you can activate the PDF download on the client side by simply pointing the source of the iframe to the PDF download page. After that, you can either go to a new page or simply show the text of gratitude, which is on the page with iframe.

+6
source

If the file has just been downloaded, no preprocessing is performed, you can try the following:

 Response.AddHeader("Refresh", "12;URL=nextpage.aspx"); 

Where is the number of seconds before the update :)

+4
source

In HTTP, a request can have only one response. Since the first answer is a PDF file, the second answer (i.e., Redirection) cannot be implemented.

You can try redoing two pages by redirecting them to thanks.aspx and starting automatic loading thanks.aspx.

+1
source

A Response.Redirect does send a response to the browser, which basically says that this resource has moved to a different URL. However, you are also trying to send the file in response, so these two things are likely to collide with each other. Try sending a little JavaScript that will send them to the page you want to send, instead of using Response.Redirect.

 ScriptManager.RegisterStartupScript(Me, Me.GetType(), "redirectScript", "window.location.href='whateverurlhere.aspx';", True) 
0
source

See the article mentioned in this accepted answer: fooobar.com/questions/267699 / ... (direct link: http://gruffcode.com/2010/10/28/detecting-the-file-download-dialog-in -the-browser / )

The idea is to set a cookie and send it along with the file. In the meantime, you allow the wait page to block the user interface while it waits for the cookie to appear.

0
source

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


All Articles