主要对象 [英] Pricipal object

查看:53
本文介绍了主要对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将pricipall对象附加到身份的位置。


全局文件

并且每次将用户角色附加到主对象时都是必要的。 。


amit

---

外发邮件已通过无病毒验证。

经检查AVG反病毒系统( http://www.grisoft.com)。 />
版本:6.0.572 /病毒数据库:362 - 发布日期:2004年1月27日

解决方案

application_authenticaterequest

和是的每个请求本身都是独一无二的。从服务器的角度来看,你说这个用户属于这个用户的唯一方式是

a。会话ID

b。基于认证的校长


-


问候,

HD

" ; Amit Agarwal < ammnbgd @雷迪夫网>在消息中写道

新闻:eS ************** @ TK2MSFTNGP10.phx.gbl ...

这里是哪里的地方将pricipall对象附加到身份。

全局文件
并且每次将用户角色附加到主要对象时都是必要的。

amit

---
发送邮件经过无病毒认证。
由AVG反病毒系统检查( http://www.grisoft.com)
版本:6.0.572 /病毒库:362 - 发布日期:2004年1月27日


我假设您正在谈论这样做以及身份验证。这里

就是我所做的,而且效果很好。这取自

MSDN上的一个例子。
http://msdn.microsoft.com/library/de...SecNetHT04.asp

''在global.asax

Sub Application_AuthenticateRequest(ByVal发送者为对象,ByVal e As

EventArgs)

''尝试验证用户时触发


''提取表单身份验证cookie

Dim cookieName As String = FormsAuthentication.FormsCookieName

Dim authCookie As HttpCookie = Context.Request.Cookies(cookieName)


如果authCookie什么都没有那么

''没有认证cookie。

返回

结束如果


Dim authTicket As FormsAuthenticationTicket


尝试

authTicket = FormsAuthentication.Decrypt(authCookie.Value)

Catch ex As Exception

''记录异常详情(为简单起见省略)

返回

结束尝试


如果authTicket是什么都没有

''Cookie无法解密。

返回

结束如果


昏暗的角色()As String = {" role1"," role2"," role3"}


''创建一个Identity对象

Dim id As FormsIdentity = New FormsIdentity(authTicket)


''此委托人将在整个请求中流动。

Dim principal As GenericPrincipal = New GenericPrincipal(id,roles)

''将新的主体对象附加到当前的HttpContext对象

Context.User = principal

End Sub


Private Sub Page_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load

''放置用户代码初始化这里的页面

Dim p As System.Security.Principal.IPrincipal =

HttpC ontext.Current.User


''用户名

Response.Write("您的用户名" &安培; p.Identity.Name)


如果p.IsInRole(" role1")那么

Response.Write(" User is in role1")

否则

Response.Write(用户不在role1中)

结束如果

结束Sub


" Amit Agarwal" < ammnbgd @雷迪夫网>在消息中写道

新闻:eS ************** @ TK2MSFTNGP10.phx.gbl ...

这里是哪里的地方将pricipall对象附加到身份。

全局文件
并且每次将用户角色附加到主要对象时都是必要的。

amit

---
发送邮件经过无病毒认证。
由AVG反病毒系统检查( http://www.grisoft.com)
版本:6.0.572 /病毒库:362 - 发布日期:2004年1月27日


thx for your reply ...

是user.identity.name

可在课堂模块中访问ascx控件?


i怀疑没有!


amit


" Michael" < raterus @本地>在消息中写道

news:ek ************** @ TK2MSFTNGP09.phx.gbl ...

我假设你在说话与身份验证一起执行此操作。这里
就是我做过的,而且效果很好。这是从MSDN上的一个例子中得到的。
http://msdn.microsoft.com/library/de...SecNetHT04.asp
''在global.asax中
Sub Application_AuthenticateRequest(ByVal sender As Object,ByVal e As
EventArgs)
''尝试验证用户时触发

''提取表单身份验证cookie
Dim cookieName As String = FormsAuthentication.FormsCookieName
Dim authCookie As HttpCookie = Context.Request.Cookies(cookieName)

如果authCookie什么都没有那么
''没有认证cookie。
返回结束

Dim authTicket As FormsAuthenticationTicket

尝试
authTicket = FormsAuthentication.Decrypt(authCookie.Value)
Catch ex As Exception
''记录异常详情(为简单起见省略)
返回
结束尝试

如果authTicket什么都没有那么
''Cookie失败解密。
返回
结束如果

Dim roles()As String = {" role1"," role2"," role3"}
< br'>''创建一个Identity对象
Dim id As FormsIdentity = New FormsIdentity(authTicket)

''这个主体将在整个请求中流动。
Dim principal As GenericPrincipal = New GenericPrincipal(id,
roles)''将新的主体对象附加到当前的HttpContext
对象Context.User = principal

End Sub

Private Sub Page_Load(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理MyBase.Load
''用户代码初始化页面他重新评估:作为System.Security.Principal.IPrincipal =
HttpContext.Current.User

''用户名
Response.Write("您的用户名) &安培; p.Identity.Name)

如果p.IsInRole(" role1")那么
Response.Write(用户在角色1中)
其他
Response.Write(User not not in role1)
结束如果
结束Sub

Amit Agarwal < ammnbgd @雷迪夫网>在消息中写道
新闻:eS ************** @ TK2MSFTNGP10.phx.gbl ...

将pricipall对象附加到的位置在哪里身份。

全局文件
并且每次将用户角色附加到主要对象时都是必要的。

amit

- -
发送邮件经过无病毒认证。
由AVG反病毒系统检查( http://www.grisoft.com)
版本:6.0.572 /病毒数据库:362 - 发布日期:2004年1月27日



---

外发邮件经过认证无病毒。

由AVG反病毒系统检查( http://www.grisoft.com)

版本:6.0 .572 /病毒库:362 - 发布日期:2004年1月27日


where is the place to attach pricipall object to identity.

global file
and is it necessary to attach each time user roles to principal object..

amit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.572 / Virus Database: 362 - Release Date: 1/27/2004

解决方案

application_authenticaterequest

and yes each request is a unique by itself. the only way you say that it
belong to this user from a server''s prespective is
a. session id
b. principal based on authentication

--

Regards,
HD
"Amit Agarwal" <ammnbgd@rediffcom> wrote in message
news:eS**************@TK2MSFTNGP10.phx.gbl...

where is the place to attach pricipall object to identity.

global file
and is it necessary to attach each time user roles to principal object..

amit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.572 / Virus Database: 362 - Release Date: 1/27/2004



I assume you are talking about doing this along with authentication. Here
is what I''ve done, and it works great. This was taken from an example on
MSDN.
http://msdn.microsoft.com/library/de...SecNetHT04.asp

''in global.asax
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As
EventArgs)
'' Fires upon attempting to authenticate the user

''Extract the forms authentication cookie
Dim cookieName As String = FormsAuthentication.FormsCookieName
Dim authCookie As HttpCookie = Context.Request.Cookies(cookieName)

If authCookie Is Nothing Then
''There is no authentication cookie.
Return
End If

Dim authTicket As FormsAuthenticationTicket

Try
authTicket = FormsAuthentication.Decrypt(authCookie.Value)
Catch ex As Exception
'' Log exception details (omitted for simplicity)
Return
End Try

If authTicket Is Nothing Then
'' Cookie failed to decrypt.
Return
End If

Dim roles() As String = {"role1","role2","role3"}

'' Create an Identity object
Dim id As FormsIdentity = New FormsIdentity(authTicket)

'' This principal will flow throughout the request.
Dim principal As GenericPrincipal = New GenericPrincipal(id, roles)
'' Attach the new principal object to the current HttpContext object
Context.User = principal
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
''Put user code to initialize the page here
Dim p As System.Security.Principal.IPrincipal =
HttpContext.Current.User

''username
Response.Write ("Your username " & p.Identity.Name)

If p.IsInRole("role1") Then
Response.Write("User is in role1")
Else
Response.Write("User is not in role1")
End If
End Sub

"Amit Agarwal" <ammnbgd@rediffcom> wrote in message
news:eS**************@TK2MSFTNGP10.phx.gbl...

where is the place to attach pricipall object to identity.

global file
and is it necessary to attach each time user roles to principal object..

amit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.572 / Virus Database: 362 - Release Date: 1/27/2004



thx for ur reply...
is user.identity.name
accessible in class modules and ascx controls?

i doubt no!

amit

"Michael" <raterus@localhost> wrote in message
news:ek**************@TK2MSFTNGP09.phx.gbl...

I assume you are talking about doing this along with authentication. Here
is what I''ve done, and it works great. This was taken from an example on
MSDN.
http://msdn.microsoft.com/library/de...SecNetHT04.asp
''in global.asax
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As
EventArgs)
'' Fires upon attempting to authenticate the user

''Extract the forms authentication cookie
Dim cookieName As String = FormsAuthentication.FormsCookieName
Dim authCookie As HttpCookie = Context.Request.Cookies(cookieName)

If authCookie Is Nothing Then
''There is no authentication cookie.
Return
End If

Dim authTicket As FormsAuthenticationTicket

Try
authTicket = FormsAuthentication.Decrypt(authCookie.Value)
Catch ex As Exception
'' Log exception details (omitted for simplicity)
Return
End Try

If authTicket Is Nothing Then
'' Cookie failed to decrypt.
Return
End If

Dim roles() As String = {"role1","role2","role3"}

'' Create an Identity object
Dim id As FormsIdentity = New FormsIdentity(authTicket)

'' This principal will flow throughout the request.
Dim principal As GenericPrincipal = New GenericPrincipal(id, roles) '' Attach the new principal object to the current HttpContext object Context.User = principal
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
''Put user code to initialize the page here
Dim p As System.Security.Principal.IPrincipal =
HttpContext.Current.User

''username
Response.Write ("Your username " & p.Identity.Name)

If p.IsInRole("role1") Then
Response.Write("User is in role1")
Else
Response.Write("User is not in role1")
End If
End Sub

"Amit Agarwal" <ammnbgd@rediffcom> wrote in message
news:eS**************@TK2MSFTNGP10.phx.gbl...

where is the place to attach pricipall object to identity.

global file
and is it necessary to attach each time user roles to principal object..

amit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.572 / Virus Database: 362 - Release Date: 1/27/2004



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.572 / Virus Database: 362 - Release Date: 1/27/2004


这篇关于主要对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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