Direction to a new page after file upload

When I try to redirect to a new page after downloading the file, it does not work. Do I need to delete or modify anything in this code? the debugger does not reach it

byte[] fileData = (byte[])sqlRead[3]; Response.Clear(); Response.AppendHeader("content-disposition", "attachment; filename=" + sqlRead[2]); Response.ContentType = "application/octet-stream"; Response.BinaryWrite(fileData); Response.Flush(); Response.End(); Response.Clear(); Response.Redirect("Questions.aspx"); 
+4
source share
5 answers

Take out

 Response.End(); 

Response.End kills the whole response, after that there will be nothing.

The End method calls the web server to stop processing the script and return the current result. the remaining contents of the file are not processed.

+3
source

Andrew is right about Response.End termination. I don’t think that removing this will help, however, since it will just affect the file you are sending.

You can get the effect you want with other tricks. For example, you can use some JS on a page with a DL link to perform client-side redirection.

change

What I suggest is that you add secondary behavior to your download link in order to click on it, and downloads the file, and modifies the current page. This might work better if a click starts a timer that redirects after a second or so.

+3
source

I'm not an ASP guy, but you also need to move the Redirect call over any call that writes something to the response body.

Try placing a call to Redirect() right after Response.Clear()

The redirect URL is passed in the header of the HTTP response, thereby causing it after the body has been generated (and thus the header has already been generated and sent) will not be displayed without effect or error.

0
source

Do not use response.end () / It will abruptly terminate the request processing flow.

0
source

You can try to remove this entire block:

 Response.Flush(); Response.End(); Response.Clear(); 

I think the problem may be that calling Flush() causes the content to be sent to the browser, so it's too late to add the HTTP redirect headers that are added when Redirect() called.

0
source

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


All Articles