[英]asp.net page authentication security level
I am currently using: 我目前正在使用:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["SecurityLevel"] != "A") //If the logged in user is not Admin
{
//disable the following images and links
GridView1.Visible = false;
GridView2.Visible = false;
}
}
to block visibility of certain items on a webpage to those who do not have admin privileges. 阻止网页上某些项目的显示给那些没有管理员权限的用户。
My questions is: how can I rewrite this code so that it blocks visibility to anyone who is not an Admin OR logged in as a User (these being the 2 security levels my site uses)? 我的问题是:我该如何重写此代码,以便阻止非管理员或以用户身份登录(这是我的网站使用的2个安全级别)的任何人的可见性?
I have tried writing if (Session["SecurityLevel"] != "A" || "U")
to use an OR operator but this will not compile. 我尝试编写if (Session["SecurityLevel"] != "A" || "U")
以使用OR运算符,但这将无法编译。
does anyone know an easy was I can rewrite this to say if != admin or user
有谁知道一个容易的事,我可以改写这个说, if != admin or user
or potentially if = unauthenticated
或if = unauthenticated
可能
I have done some searches and most point to setting the authentication mode to forms and adding an authorize class to the controller or something like that but I really only need this authentication for one page on my site 我已经进行了一些搜索,大多数指向设置身份验证模式为表单并将授权类添加到控制器或类似的东西,但实际上我只需要对网站上的一页进行此身份验证
asp.net website in c# C#中的asp.net网站
You would write if (Session["SecurityLevel"] != "A" || "U")
您将编写以下内容: if (Session["SecurityLevel"] != "A" || "U")
as 如
if (Session["SecurityLevel"] != "A" || Session["SecurityLevel"] != "U")
but you may want to use an &&
condition 但您可能要使用&&
条件
if (Session["SecurityLevel"] != "A" && Session["SecurityLevel"] != "U")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.