开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜