Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in asp.net what sets Request.IsAuthenticated = true [duplicate]

Possible Duplicate:
asp.net membership IsApproved false but still allowing login

i am having a user register but IsApproved is false but when i check Request.IsAuthenticated it still returns true.

Do you know how this can happen?

like image 722
leora Avatar asked Jul 31 '09 14:07

leora


People also ask

How is IsAuthenticated set true?

Using the Codebool isAuthenticated = Request. IsAuthenticated; the result is always true . It's not what we expect when signout is performed.

How does request IsAuthenticated work?

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. Once it has done this, it replaces the GenericIdentity in Context.

What is IsAuthenticated?

Definition. The IsAuthenticated property is a boolean value that indicates whether the current user is authenticated (logged in). The property value is a boolean true if the current user is authenticated, otherwise false.

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);


1 Answers

HttpRequest.IsAuthenticated returns true if HttpContext.User.Identity is not null and it's IsAuthenticated property returns true.

The current identity is set in the FormsAuthenticationModule, but it has nothing to do with your MembershipProvider. In fact, it doesn't even reference it. All it does is check to see if the authentication cookie is still set and is still valid (as is, has not expired).

I think the problem is that you are calling one of the FormsAuthentication methods like RedirectFromLoginPage, which is settings the authentication cookie. If you need to wait until the user is approved, then you need to make sure you are not setting the cookie.

like image 142
Richard Szalay Avatar answered Oct 01 '22 23:10

Richard Szalay