如果用户在asp.net中按F5或刷新,如何防止数据发送? [英] how to prevent data from sending if user press F5 or refresh in asp.net?

查看:22
本文介绍了如果用户在asp.net中按F5或刷新,如何防止数据发送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 asp.net 表单应用程序我有一个错误,当用户单击 F5 或刷新时,它会输入上次数据条目中的数据.如果用户单击 F5 或刷新,他们是否会阻止发送数据?

I had asp.net form app I have a bug when the user click F5 or refresh it will enter the data from last data entry .is their is away to Prevent sending data if user click click F5 or refresh?

推荐答案

在 ASP.NET 中,通过重定向到自身,可以轻松地将页面重置为其初始状态.这里有 3 种方法可以做到:

It's easy to reset a page to it's initial state in ASP.NET by redirecting to itself. Here are 3 ways you can do it:

  1. Response.Redirect(Request.Path);

其中请求的路径以下列形式呈现:/MyApp/MyFile.aspx

In which the path to the request is presented in the following form: /MyApp/MyFile.aspx

  1. Response.Redirect(Request.RawUrl);

其中不仅公开了路径,还公开了任何查询字符串参数,例如:/MyApp/MyFile.aspx?foo=bar

In which not only is the path exposed, but also any querystring parameters like: /MyApp/MyFile.aspx?foo=bar

  1. Response.Redirect(Request.Url.ToString());

其中不仅公开了路径和查询字符串参数,而且还提供了以下形式的绝对引用:MyServer/MyApp/MyFile.aspx?foo=bar

In which not only is the path and querystring parameters exposed, but made available as an absolute reference in the form: MyServer/MyApp/MyFile.aspx?foo=bar

这篇关于如果用户在asp.net中按F5或刷新,如何防止数据发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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