Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between HttpContext.Current.Request.IsAuthenticated and HttpContext.Current.User.Identity.IsAuthenticated?

Tags:

asp.net

What is the difference between HttpContext.Current.Request.IsAuthenticated and HttpContext.Current.User.Identity.IsAuthenticated?

Which one would you use in which situation?

like image 301
Anthony Avatar asked Sep 04 '09 14:09

Anthony


People also ask

What is HttpContext current user identity?

It just holds the username of the user that is currently logged in. After login successful authentication, the username is automatically stored by login authentication system to "HttpContext.Current.User.Identity.Name" property.

How do you set HttpContext user identity for an application manually?

You can achieve this by manually settings HttpContext. User: var identity = new ClaimsIdentity("Custom"); HttpContext. User = new ClaimsPrincipal(identity);

How does request IsAuthenticated work?

Identity with a new IIdentity object that will return true from its IsAuthenticated property. Request. IsAuthenticated will then return true . In the case of Forms authentication, the forms authentication module uses the encrypted authentication ticket contained in the authentication cookie to authenticate the user.


1 Answers

There's absolutely no difference. Checkout HttpContext.Current.Request.IsAuthenticated implementation:

public bool IsAuthenticated {     get     {         return (((this._context.User != null) &&                   (this._context.User.Identity != null)) &&                  this._context.User.Identity.IsAuthenticated);     } } 
like image 50
Darin Dimitrov Avatar answered Sep 20 '22 12:09

Darin Dimitrov