如何在response.transmitfile之后刷新页面? [英] How to refresh page after response.transmitfile?

查看:116
本文介绍了如何在response.transmitfile之后刷新页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿......我需要刷新我的页面或在文件下载后重定向...



我尝试了什么:



已经尝试将刷新附加到响应标题...没有工作...也尝试在response.end之前使用response.redirect ...不工作...

解决方案

使用 Cookies [ ^ ]来完成这项任务

请参阅此文章 [ ^ ]你会对此有所了解,而不是隐藏图像只需使用位置重载()方法重新加载页面 [ ^ ]


< blockquote>不幸的是,这是不可能的。



TransmitFile 发送包含您要下载的文件的响应。该响应只能包含与下载相关的HTTP标头。

HttpResponse.TransmitFile [ ^ ]



重定向会告诉浏览器中止当前请求并发出全新请求,这将取消下载。

HttpResponse.Redirect [ ^ ]



只有在您返回HTML页面时,刷新标题才有效。

元刷新 - 维基百科 [ ^ ]



AFAIK,无法通过服务器或Javascript代码知道下载何时完成。您可以做的最好的事情是在短暂超时后使用Javascript导航到另一个页面,或者在下载完成后显示用户手动点击的链接。


基本上你有按照以下步骤。

当你传输文件时,你也会在你的回复中添加一个cookie。

并在客户页面上你会写一个javascript函数来检查每500毫秒后该cookie。

一旦收到cookie,你可以使用重定向功能或任何你想要的东西并删除co​​okie。

使用 this [ ^ ]以供参考


Hey...I need to refresh my page or redirect it after a file download...

What I have tried:

Already tried to append refresh to response header...havent worked...also tried to use response.redirect before response.end...not working either...

解决方案

Use Cookies[^] to achieve this task
refer this article[^] you will get some idea on this, instead of hiding the image just reload the page using Location reload() Method[^]


Unfortunately, that's not possible.

TransmitFile sends a response containing the file you want to download. That response can only contain HTTP headers related to the download.
HttpResponse.TransmitFile[^]

Redirect would tell the browser to abort the current request and make a brand new request, which would cancel the download.
HttpResponse.Redirect[^]

And the "refresh" header would only work if you were returning an HTML page.
Meta refresh - Wikipedia[^]

AFAIK, there isn't a reliable way to know when the download has completed, either from the server or from Javascript code. The best you can do is use Javascript to navigate to another page after a brief timeout, or to display a link for the user to manually click on once the download has completed.


Basically you have to follow below steps.
When you are transmitting file you will also add a cookie in your response.
and on client page you will write a javascript function which will check for that cookie after every 500 milliseconds.
once you receive the cookie then you can use redirect functionality or whatever you want and delete the cookie.
use this[^] for reference


这篇关于如何在response.transmitfile之后刷新页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆