如何限制直接网址访问 [英] How to restrict direct url accees

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

问题描述



在我的Web应用程序中,使用表单身份验证.成功登录后将首次加载登录页面(Login.aspx)重定向到Default.aspx表单.在默认页面列表中的所有菜单中,单击菜单,将页面加载到默认页面中(使用Telerik控件).
现在我面临一个问题,当用户键入直接URL时(假设页面名称之一是page1.aspx),例如:Myapplication/page1.aspx页面正在加载,我想对此进行限制.

请为此提出一个解决方案.

Hi,

In my web application, using form authentication. First loading login page(Login.aspx) after successful login redirect to Default.aspx form. In default page list all menus, clicking on menu the page load inside default page(Using Telerik control).
Now i am facing a issue, While user typing a direct url (Suppose one of the page name is page1.aspx) eg: Myapplication/page1.aspx the page is loading i want to restrict this.

Please suggest a solution for this.

推荐答案

您可以在web.config中使用位置标记进行所有操作:

You can do all this in web.config with the location tag:

<location path="Page1.aspx" allowoverride="false">
   <system.web>
     <authorization>
       <deny users="?" roles="TEMP" />
       <allow roles="ADMIN, USERS" />
     </authorization>
   </system.web>
 </location>




请查看以下链接以获取详细信息:

https://wiki.asp.net/page.aspx/653/aspnet-webconfig--位置和身份验证标签/ [ ASP.NET成员资格-第1部分 [




Please see the following links for details:

https://wiki.asp.net/page.aspx/653/aspnet-webconfig--location-and-authroization-tags/[^]

ASP.NET Membership - Part 1[^]


搜索和研究同情变量"和网站管理员(可选)

登录时,用作存储登录信息的会话变量,

每个页面或母版页都必须在会话中检查该变量,如果可以的话,则允许用户加载页面,否则会将其重定向到登录页面

在登录页面中:

Session.add("myvarableName","Value")

在母版页或每页加载中
c#
search and study "sassion variables" and site master (optional)

when logging in, use as session variable for storing login info,

every page or your master page must check for the that variable in session, if it is okay, it lets the user to load page, otherwise it redirects it to login page

in login page:

Session.add("myvarableName", "Value")

in master page, or in every page load
c#
if (Session["myvariableName"]!=Null & Session["myvariable"]!= "value") Response.Redirect("Login.aspx",true);



vb .net



vb .net

if Session("myvariableName") isnot nothing and Session("myvariable") = "value"
Response.Redirect("Login.aspx",true)
end if


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

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