如何防止网页的直接访问? [英] How to prevent direct access of webpage?

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

问题描述

我正在使用C#,ASP.NET,VS2005.如何防止用户直接访问网页?即,当用户输入"www.google.com/thispage"时,用户将被带回到"www.google.com".用户只能通过"www.google.com"上的链接访问"www.google.com/thispage".谢谢!任何帮助表示赞赏.

我想访问用户通过前门"(www.google.com),而不是通过手动输入(www.google.com/thispage).仅通过单击(www.google.com)上的链接/按钮,它将把用户定向到(www.google.com/thispage).

Hi I am using C#, ASP.NET, VS2005. How can I prevent users from directly accessing a webpage? i.e. when a user enters - "www.google.com/thispage" the users is directed back to "www.google.com". The users can only access "www.google.com/thispage" via a link on "www.google.com". Thanks! Anyhelp is appreciated.

I want to access a user go through the "front door"(www.google.com) and not by entering manually (www.google.com/thispage). Only by clicking a link/button on (www.google.com) then it will direct the user to (www.google.com/thispage).

推荐答案

put Response.Redirect("youpageurl");在页面加载事件中.

put Response.Redirect("youpageurl"); in page load event.
Like
Protected Void thispage_load(object sender, eventArgs e)
{
     Response.Redirect("www.google.com");
}


如果您使用解决方案1,则将永远无法访问该页面.它将始终重定向到www.google.com.您必须检测用户是否尝试直接访问它.您可以添加QueryString(www.google.com/thispage?LinkClicked=Yes)或使用会话.

如果Request.QueryString("LinkClicked")!="是"
{
Response.Redirect("www.google.com");
}
If you use Solution 1 you would never access that page. It will always redirect to www.google.com. You have to detect if user is trying access it directly. You can add QueryString(www.google.com/thispage?LinkClicked=Yes) or use Session.

If Request.QueryString("LinkClicked") != ''Yes''
{
Response.Redirect("www.google.com");
}


这篇关于如何防止网页的直接访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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