mmutilva
mmutilva

Reputation: 18994

ASP.Net - Save some info in the Session within a custom MembershipProvider

I want to save some info in the Session when the users successfully logins with my custom MembershipProvider, but I have no access to the Session in the provider's ValidateUser method.

public class CustomMembershipProvider : MembershipProvider
{
    /* Override other methods and properties here */

    public override bool ValidateUser(string username, string password)
    {
        /* do something to validate the username and password 
         * and set the validUser variable */
        if (validUser)
        {
            /* want to store some info in the Session here, but I can't access
             * it here, because this is not a Page */
        }
        return validUser;                
    }
}

How can I do that?

Upvotes: 0

Views: 711

Answers (1)

Arief
Arief

Reputation: 6085

You can use HttpContext.Current.Session
You need to reference System.Web first. This will get the Session on which the current thread is running.

Example:

HttpContext.Current.Session["UserWhatevetProperty"] = validUser.WhateverProperty;

Upvotes: 3

Related Questions