Forms窗体验证

复制现有应用程序的 Global.asax 文件中的以下代码,将这些角色分配给 Application_AuthenticateRequest 事件处理程序中的验证用户: Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
if (not(HttpContext.Current.User is Nothing)) then
if HttpContext.Current.User.Identity.AuthenticationType = "Forms" then
Dim id as System.Web.Security.FormsIdentity
id = HttpContext.Current.User.Identity

Dim MyRoles(2) As String
MyRoles(0) = "Manager"
MyRoles(1) = "Admin"
HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(id,MyRoles)
End if
End if
End sub
返回页首
检查用户角色并在 ASPX 页中实现程序逻辑
下列步骤说明如何根据验证用户所属的角色实现并控制程序逻辑。1. 创建名称为 Sample.aspx 的新 .aspx 页,并粘贴以下代码: <%@ Page Language="VB" %>
<%@ Import Namespace="System.Web" %>

<script runat=server>
Sub Page_Load(Src As Object, E As EventArgs)
 if User.IsInRole("Admin") then
  Response.Write ("You are an Administrator")
 Else
  Response.Write ("You do not have any role assigned")
 End if
End Sub

</script>
 
2. 将 Sample.aspx 保存到现有应用程序中。浏览到该页以测试它。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值