Can I add something to a user session in a user membership package?

I am implementing a custom MemberhipProvider to transfer login information to a custom business object that we use in several other places in our company. But as soon as we get authentication, I want to save this initialized business object in a session, which will be used later on other pages. Let me give you an example.

public override bool ValidateUser(string username,string password)
{
    try
    {
        // I want to keep this "object" in the Session to be used later on
        CustomBusinessObject object = new CustomBusinessObject(username, password);

        return true;
    }
    catch (CustomBusinessAuthenticationException)
    {
        return false;
    }
}

Is there any way to do this? I did not immediately see a way to access the Session object through the implementation of this custom MembershipProvider.

+3
source share
2 answers

, System.Web.HttpContext.Current. , , HttpContext.Current null, , null, .

public object CustomObject
{
    get
    {
        if(System.Web.HttpContext.Current == null)
        {
            return null;
        }
        return System.Web.HttpContext.Current.Session["CustomObject"];
    }
    set
    {
        if(System.Web.HttpContext.Current != null)
        {
            System.Web.HttpContext.Current.Session["CustomObject"] = value;
        }
    }
}
+3

System.Web.HttpContext.Current.Session.

, System.Web.HttpContext null, - ASP.Net , , ASP.Net.

0

Source: https://habr.com/ru/post/1710634/


All Articles