Principal/Identity questions

C

Craig Buchanan

I've integrated role-based, forms authentication in my ASP.net application.
I have a few remaining issues that I hope to resolve. Here are some of my
questions:

1). I would like to access the Identity properties from within a web
custom control. It appears that the HTTPcontext is not available. What is
the 'proper' way to access the Identity info in this situation?

2). Is there a way to add additional Properties to the Identity object
such that they are available in the
Threading.Thread.CurrentPrincipal.Identity hierarchy?

3). Can someone explain in laymans terms what the Principal and Identity
objects are?

Thanks,

Craig Buchanan
 
J

John Saunders

Answers inline:

Craig Buchanan said:
I've integrated role-based, forms authentication in my ASP.net application.
I have a few remaining issues that I hope to resolve. Here are some of my
questions:

1). I would like to access the Identity properties from within a web
custom control. It appears that the HTTPcontext is not available. What is
the 'proper' way to access the Identity info in this situation?

You should access HttpContext.Current when you need the context in a control
or something like that.
2). Is there a way to add additional Properties to the Identity object
such that they are available in the
Threading.Thread.CurrentPrincipal.Identity hierarchy?

You can't add properties to the Identity, but you can create your own
Principal which has as many properties as you like. Just derive from
GenericPrincipal and start adding properties.
3). Can someone explain in laymans terms what the Principal and Identity
objects are?

I think that the Identity is who is making the request, but the Principal is
who is making the request and what they're allowed to do. Note that you use
User.IsInRole, not User.Identity.IsInRole.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top