开发者

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

开发者 https://www.devze.com 2023-01-23 10:19 出处:网络
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.

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 meth开发者_开发百科ods 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?


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

精彩评论

暂无评论...
验证码 换一张
取 消