禁止直接访问 ASP.NET 中的特定网页 [英] disable a direct access to a specific web page in ASP.NET

查看:33
本文介绍了禁止直接访问 ASP.NET 中的特定网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种可靠的方法可以禁用对特殊网页的直接访问?我的意思是我只想通过单击按钮来打开它,例如.我知道我可以使用此代码访问网页,但它无法阻止直接访问网页(粘贴网址或输入网址):

Is there a trusted way to disable the direct access to an special web page? I mean I want to open it only by clicking on a Button for example. I know I can access to the webpage by using this code but It can not prevent accessing to the web page directly (Pasting the url or typing it):

 Response.Redirect("~/Code.aspx")

谢谢

推荐答案

在源页面上创建一个标记到一个隐藏字段中.向您的按钮添加 PostBackUrl 属性并让它指向您的目标页面.

On the source page create a token into a hiddenfield. To your button add PostBackUrl property and let it point to your destination page.

在目标页面上,您可以验证请求是否来自您允许的源页面.而且您不需要使用会话及其所有缺点.

On the destination page you can validate that the request was made from your allowed source page. And you dont need to use session and all its drawback.

检查这个 链接 了解有关如何使用上述属性的详细信息.

Check this Link for detailed information about how to use the mentioned property.

这篇关于禁止直接访问 ASP.NET 中的特定网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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