限制某些页面的功能或用户界面在Asp.Net身份验证的用户 [英] Restricting certain page functionality or user interface to authenticated users in Asp.Net

查看:101
本文介绍了限制某些页面的功能或用户界面在Asp.Net身份验证的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Asp.Net/C#来建立一个application.I现在用表单验证。我有这样,我的许多认证(非匿名)用户的要求仅限于某些网页的功能或用户interface.I猜测登录控制可用于仅通过身份验证的匿名VS users.So我的问题是,当我知道,某些页面组件是从特定的身份验证的用户隐藏的,我该怎么办去it.Do你觉得我需要用这个就Page_Load事件隐藏组件具有这种要求的网页。

I am using Asp.Net/C# to build an application.I am using Forms Authentication.I have a requirement such that many of my authenticated (not anonymous) users are restricted to certain page functionalities or user interface.I guess the Login Control could be used for only Authenticated vs Anonymous users.So my question is when I know that certain page component is to be hidden from particular authenticated users , how do I go about it.Do you think I need to use this on the page_load event to hide the components for the pages which have such requirements.

// Is this Tito visiting the page?
string userName = User.Identity.Name;
if (string.Compare(userName, "Tito", true) == 0)
 // This is Tito, SHOW the Delete column
 FilesGrid.Columns[1].Visible = true;
else
 // This is NOT Tito, HIDE the Delete column
 FilesGrid.Columns[1].Visible = false;

是否有更好的方法来完成this.Any帮助是非常AP preciated.Thanks

Are there better approaches to accomplish this.Any help is much appreciated.Thanks

推荐答案

在这里,您可以使用Membeship用户类的 RolePrincipal 给用户分开。

Here you can use the Membeship User class and RolePrincipal to separate the users.

if(HttpContext.Current.User.IsInRole("Level1"))
{
    FilesGrid.Columns[1].Visible = true;
}
else
{
    FilesGrid.Columns[1].Visible = false;
}

所以,你做,并把你的用户在不同的会员的名字,然后告诉你他们是取决于成员的角色不同的控件。

So you make and place your user in different membership names, and then you show them different controls that are depend on the membership role.

某些链接:

http://msdn.microsoft.com/en-us/library/ ff648345.aspx

http://msdn.microsoft.com/en-us/library/system.web.security.roleprincipal.isinrole.aspx

这篇关于限制某些页面的功能或用户界面在Asp.Net身份验证的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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