简体   繁体   中英

ASP.net attachment then refresh page

I am working on ac# project using ASP .net.

I have a list of reports with a hyperlink for each, which calls the web server, retrieves a PDF and then returns the PDF for the user to save or open:

ASPX page:

<table>
<tr>
<td>
    <a href="#" onclick="SubmitFormToOpenReport();">Open Report 1</a>
<td>
</tr>
...
</table>

ASP.Net:

context.Response.Clear();
context.Response.AddHeader("content-disposition", "attachment;filename=report.pdf");
context.Response.Charset = "";
context.Response.ContentType = "application/pdf";
context.Response.BinaryWrite(myReport);
context.Response.Flush();

This works as expected, however I would like it to also refresh the page with an updated list.

I am having trouble as the single request/response is returning the report.

Is there a way to refresh the page as well?

While there is a correct response, feel free to include answers which details alternative solutions/ideas for doing this.

Unfortunately your current approach is a dead end. The nature of HTTP is single request, single response. A response can only have one code - "OK, here is some data, please download it". "Go here instead" is a different code. You're describing something much more complex - a sequence of instructions. First "here is a file", then "redirect yourself to another resource". The implications of making this work should be a clue - when should the browser redirect? When the user selects a location to save the file? After the file is finished downloading?

To do what you're describing, you could have the JavaScript open the PDF in a new window and also re-load the current window.

尝试在context.Response.Flush();后使用response.redirect(request.url.tostring) context.Response.Flush();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM