Click here to Skip to main content
15,922,574 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In asp.net security, when we write : httpcontext.user.identity.isauthenticated()

here httpcontext is a namespace
user is a property
identity is a property.
isauthenicated is a method...

i am confused about 'USER' and 'IDENTITY' properties...how come we can access a property WITHIN A PROPERTY ???
Posted

Wrong:

HttpContext - This is a static class.
User - Is a property but inherits IPrincipal.
Identity - Is a property in the the IPrinciple interface.
IsAthenticated - This is a method that returns if the current user is athenticated.

http://msdn.microsoft.com/en-us/library/system.web.httpcontext.aspx[^]
 
Share this answer
 
You can access a property within a property because that property User, that implements IPrincipal, has a method Identity that returns an object that implements the IIdentity interface. So each time you operate on the return value of that property. It would technically not matter whether a property or method was used to return the object instance. If User.Identity.isAuthenticated() would be User.GetIdentity().isAuthenticated() it could also work fine, although it would be somewhat more strange to read.

So, because the property is of a certain class you can immediately start calling properties and methods when you access them. Like httpcontext.User.Identity.isAuthenticated() returns a boolean, but to store it as a string you can also do this httpcontext.User.Identity.isAuthenticated().toString() without any problems.

Good luck!
 
Share this answer
 
It's simple: think of each class as a box.

Each box can be opened, and contains various drawers - each draw is a property of the box.

If you put a box (SmallBox) inside the drawer of another box (BigBox):
BigBox myBigBox = new BigBox();
myBigBox.DrawerSeven.Box = new SmallBox(nameOfSmallBox);
Then you would access it's drawers as:
SmallBox mySmallBox = myBigBox.DrawerSeven.Box;
string s = mySmallBox.DrawerFour.Name;
You could combine these and say:
string s = myBigBox.DrawerSeven.Box.DrawerFour.Name;
and get the same result.

Box is a property of DrawerSeven, which is a property of BigBox.
Name is a property of DrawerFour, which is a property of SmallBox.
 
Share this answer
 
A property can be an object, itself having properties...
 
Share this answer
 
The context of what you think as of "inside property" has absolutely nothing special compared to other places where you write your code. As I can understand, you're talking about the code "inside" a property getter or setter (because — what else?). So, you can do whatever you need. This includes accessing some other property of the same or any other type.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900