检测页面刷新并防止其重定向到错误页面 [英] Detect page refresh and prevent it from redirecting to Error Page

查看:77
本文介绍了检测页面刷新并防止其重定向到错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好专家,

我正在开发c#asp.net网页.
我必须禁止在其他标签页或其他浏览器窗口中重新打开该网站.
我能够处理生成唯一的PageId.当用户在另一个标签或新的浏览器窗口中打开相同的网站时,将生成一个新的页面ID,
我对照当前页面ID对其进行了检查,并将其重定向到错误页面.
但是,当我刷新页面时,我也得到了新的PageId,而不是现有的,因此它被重定向到错误页面.
我在互联网上搜索了解决方案,但这些解决方案都不对我有用.如何检测刷新?
你能指导我如何处理吗?

谢谢
RaesaRk

Hello experts,

I am working on c# asp.net web page development.
I have to disallow the site from reopening in other tabs or other browser windows.
That I am able to handle generating unique PageId. When the user opens the same site in another tab or new browser window, a new page id is generated,
I check it against the current page id and redirect it to the error page.
But when I refresh the page, I also get the new PageId and not the existing one and so it gets redirected to the error page.
I searched on internet for solutions but none of those solutions are working for me. How can I detect a refresh??
Can you please guide me on how to handle this??

Thanks
RaesaRk

推荐答案

您最好的选择是查看页面事件

http://msdn.microsoft.com/en-us/library/aa479007.aspx [ ^ ]

您可以在这些事件中添加自定义代码,以查看您的PageID是否匹配并阻止页面加载.

1.查看页面加载情况,可以进行if测试以查看页面是否回发
2.查看卸载事件

如果您不了解该帖子,请阅读本文以获取基本说明

在ASP.NET中检测刷新或回发 [ ^ ]

确保像示例中那样调用onPostBack函数,否则在刷新页面时不会生成新的ID.

< form id ="form1" runat ="server" onsubmit ="onPostBack()">
Your best bet is to look at the page events

http://msdn.microsoft.com/en-us/library/aa479007.aspx[^]

You can add your custom code in these events to see if your PageID matches and prevent the page from loading.

1. Look at the page load, you can do an if test to see if the page is post back
2. Look at the unload event

If you dont understand the post back read this article for a basic explaination

Detecting Refresh or Postback in ASP.NET[^]

Make sure the you have you are calling you function onPostBack like in the example or you wont generate the new id on refreshing the page.

<form id="form1" runat="server" onsubmit="onPostBack()">


这篇关于检测页面刷新并防止其重定向到错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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