Re: Check if user is authenticated



Use attributes on your classes and/or methods. You need something like
this:

[PrincipalPermissionAttribute(SecurityAction::Demand,

Authenticated=True,
Role="Progdir")]

The Visual Studio help puts it like this:

_______________________________________________________________________________________
PrincipalPermissionAttribute can be used to declaratively demand that users
running your code belong to a specified role or have been authenticated. Use
of Unrestricted creates a PrincipalPermission with Authenticated set to true
and Name and Role set to a null reference (Nothing in Visual Basic).

The scope of the declaration that is allowed depends on the SecurityAction
that is used. PrincipalPermissionAttribute cannot be applied at the assembly
level.

The security information declared by a security attribute is stored in the
metadata of the attribute target and is accessed by the system at run time.
Security attributes are used only for declarative security. For imperative
security, use the corresponding permission class.

Important Prior to a demand for principal permission it is necessary to
set the current application domain's principal policy to the enumeration
value WindowsPrincipal. By default, the principal policy is set to
UnauthenticatedPrincipal. If you do not set the principal policy to
WindowsPrincipal, a demand for principal permission will fail. The following
code should be executed before the principal permission is demanded:
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal).

Example
The following example demonstrates how PrincipalPermission can be used
declaratively to demand that the current user is Bob and belongs to the
Supervisor role.

Visual Basic Copy Code
<PrincipalPermissionAttribute(SecurityAction.Demand, _
Name := "Bob", Role := "Supervisor")> Public Class SampleClass

C# Copy Code
[PrincipalPermissionAttribute(SecurityAction.Demand, Name="Bob",
Role="Supervisor")]

C++ Copy Code
[PrincipalPermissionAttribute(SecurityAction::Demand,Name="Bob",
Role="Supervisor")]

J# Copy Code
/** @attribute PrincipalPermissionAttribute(SecurityAction.Demand,
Name = "Bob", Role = "Supervisor")
*/


The following example demonstrates how to demand that the current user's
identity is Bob, regardless of role membership.

Visual Basic Copy Code
<PrincipalPermissionAttribute(SecurityAction.Demand, _
Name := "Bob")> Public Class SampleClass

C# Copy Code
[PrincipalPermissionAttribute(SecurityAction.Demand, Name="Bob")]

C++ Copy Code
[PrincipalPermissionAttribute(SecurityAction::Demand,Name="Bob")]

J# Copy Code
/** @attribute PrincipalPermissionAttribute(SecurityAction.Demand, Name =
"Bob")
*/


The following example demonstrates how to demand only that the user is
authenticated.

Visual Basic Copy Code
<PrincipalPermissionAttribute(SecurityAction.Demand, _
Authenticated := True)> Public Class SampleClass

C# Copy Code
[PrincipalPermissionAttribute(SecurityAction.Demand, Authenticated=true)]
______________________________________________________________________________________

HTH


Peter


"shapper" <mdmoura@xxxxxxxxx> wrote in message
news:1165510823.833434.144220@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello,

How to I check if a user is authenticated and if it is what is its
role?

I am using Asp.Net 2.0 and forms authentication.

Thanks,

Miguel



begin 666 collapse_all.gif
M1TE&.#EA"P`+`,0``)2HX_3U]0```/'R\O[^_O?W]_GY^>[N[^KKZ_O[^^7F
MY_S\_9NMY>#AXO___]O<W=77U\_0T0``````````````````````````````
M`````````````````````````"'Y! ``````+ `````+``L```4Z( .,)"DZ
M#D$LB5$$8[JV[S"JK!L,QYW7!\1H(2@:!8H1;1=4-$8Z'L+Y& &GC0=DQ,1J
)(P!1J<0(`0`[
`
end

begin 666 copycode.gif
M1TE&.#EA#P`/`.9F`).BM[+"V*[$\(&NY:Z_U'.AWER,VIBKQBE4JIFLQ_S]
M_LO/U)*P[8JN_,73\JFXSF2%R=;>[/;Y_>OO]BM7L6Z<VB)&CZ:]["!!AJ"Y
M[VB7U9RPSM+;\9>FNZ.RR"-(EOGZ_")%CIRKP;+)\*[0_Z^^U#5EQ2E4K*FY
MSX*?V,_9YM+6W9JMRFZ7YV".Y\S7[-??ZINOS)"JX+K:_^KO^R5,FR=0HIJN
MRI:FN^;J\^#F\25-G25*F+_+W=+>\,#*X,+.Y/7V^[K%U/O]_B-'DG^G\_#T
M^\?2X7.2T4=NNI_%^B%#B=OD]_?X^Z_#[?#R^)>IQ*K![XZX\"%#BIRUYZ*Q
MQV:"I?#S^*.RQYJNS*O"[]/>]55YP2I7LW*:ZH6GZR=0I%MRC[[.\#5)8U&#
MT?_______P``````````````````````````````````````````````````
M`````````````````````````````````````````````````"'Y! $``&8`
M+ `````/``\```>?@&:"@X2%AH>"`0$$! \>*X@!99-E558+AR64"CA"89B%
M*&4S)#X``EI1&0P,+X)8DR!/.0*495\F0&8B94I2`P47MEXC%#\="D$3.A%4
M90T-'"Y=)V `3< 5&C*41DP.63L`5S J1STI944M!F1D-SP`8_/S2&5#-%MB
F3@E$AA!EVKDC<R"$(2X2-L1@D> `E"6&DB! 8*/&!PM3, 0"`#L`
`
end

.



Relevant Pages

  • Re: Check if user is authenticated
    ... PrincipalPermissionAttribute cannot be applied at the ... The security information declared by a security attribute is stored in the ... Important Prior to a demand for principal permission it is necessary to ... I am using Asp.Net 2.0 and forms authentication. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Session
    ... PrincipalPermissionAttribute can be used to declaratively demand that users ... The scope of the declaration that is allowed depends on the SecurityAction ... The security information declared by a security attribute is stored in the ...
    (microsoft.public.dotnet.framework.aspnet)
  • Request for principal permission failed
    ... PrincipalPermissionAttribute to a number of pages ... fails with a SecurityException [which is then caught and a call to a ... call-stack] fails with the doubled security exception again. ... Additionally, if the declarative security were to fail at any point, I ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: User authentication
    ... As to how the authentication works, it is all explained in the Word document and the code, but to give you a start try looking at this from Global.asax: ... // Cookie failed to decrypt. ... GenericIdentity id = new GenericIdentity; ... If you don't know how the Attributes work, you need to look them up on msdn (look for PrincipalPermissionAttribute, for example). ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Role-based security in webforms
    ... Put the roles as a comma or other separated string in your AuthCookie ... > I use role-based security in my web app. ... > PrincipalPermissionAttribute class, applying this ...
    (microsoft.public.dotnet.framework.aspnet.security)

Loading