如何限制用户查看某些页面 [英] How to restrict Users from seeing some Pages
本文介绍了如何限制用户查看某些页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
专家,
我是Uday Satardekar,
我正在开发asp.net网站.
在我的网站中,有一些页面,例如 edit_user.aspx,add_new_user.aspx
.
此功能仅适用于管理员.
我将用户类型存储在session.and这样检查,
Hi Expert,
I am Uday Satardekar,
I am developing asp.net website.
In my website there are some pages like edit_user.aspx,add_new_user.aspx
.
This facility available only for admin.
I store usertype in session.and checking like this,
if (Convert.ToInt64(Session["usertype"]) == 1)
在这里 1 是 admin , 2 是其他用户.
Here 1 for admin and 2 for other user.
then how to restrict these pages from other user.
推荐答案
在这里,您将找到一个不错的教程,它将指导您实现ASP.NET成员资格,角色和配置文件提供程序.
http://www.4guysfromrolla.com/articles/120705-1.aspx [ ^ ]
一旦使用了这种技术,就很容易做到.在包含要限制访问权限的页面的文件夹内,只需将其放入指定访问权限的适当web.config文件中即可.
您也可以观看此视频.
http://www.asp. net/general/videos/lesson-9-securing-your-web-site-with-membership-and-login-controls [
Well here you will find a nice tutorial that will guide you in implementing ASP.NET Membership, Roles and Profile provider.
http://www.4guysfromrolla.com/articles/120705-1.aspx[^]
Once you are using a technique like this, it is very easy to do so. Inside the folder that contains the pages that you would like to restrict the access just put in a proper web.config file specifying the access rights.
You can also take a look on this video.
http://www.asp.net/general/videos/lesson-9-securing-your-web-site-with-membership-and-login-controls[^]
Cheers
edit_user.aspx和add_new_user.aspx页面的页面加载事件
像这样写代码
In Page load event of both edit_user.aspx and add_new_user.aspx pages
Write the code like this
if (Convert.ToInt64(Session["usertype"]) == 1)
{
//Write the code
}
else
{
//Put a message like "you are not Authorized to see these pages"
//or
//Redirect to login page
}
这篇关于如何限制用户查看某些页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文