user2184313
user2184313

Reputation: 23

checking the existence of the user in the data store for authentication

how to check that the user is authenticated. Asp.net tells me that the user is authorized If set cookies, but I need to check whether a user with the name in my data store. Where can I add additional checks?

Upvotes: 0

Views: 71

Answers (1)

R.C
R.C

Reputation: 10565

You should Use: Request.IsAuthenticated

Check the MSDN here.

Also, Below is a great explanation taken from question: How does Request.IsAuthenticated work?

Request.IsAuthenticated is not just for forms authentciation - it is valid no matter what type of authentication is being used (Windows, Passport, Forms or our own custom scheme)

HttpRequest.IsAuthenticated will be true when the user making the request has been authenticated. Essentially, this property provides the same information as Context.User.Identity.IsAuthenticated.

At the start of a request, Context.User.Idenity contains a GenericIdentity with a null username. The IsAuthenticated property for this object will return false so Request.IsAuthenticated will be false. When an authentication module handles the Application_AuthenticateRequest event and successfuly authenticates the user it replaces the GenericIdentity in Context.User.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. Once it has done this, it replaces the GenericIdentity in Context.User.Identity with a FormsIdentity object that returns True from its IsAuthenticated property.

Upvotes: 1

Related Questions