Principal/Identity questions

  • Thread starter Thread starter Craig Buchanan
  • Start date Start date
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
 
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.
 
Back
Top