简体   繁体   中英

enable session in custom role and membership providers

I have custom role and membership providers. I want use this Project in asp.net 4 no mvc.

and use this code in web.config:

<authentication mode="Forms">
  <forms loginUrl="~/Login.aspx" timeout="2880" />
</authentication>

custom membership providers and project it's worked but session is not worked in project.

I use this code for Login:

private User SetupFormsAuthTicket(string userName, bool persistanceFlag)
    {
        User user;
        UsersContext usersContext = new UsersContext();
            user = usersContext.GetUser(userName);

        var userId = user.UserId;
        var userData = userId.ToString(CultureInfo.InvariantCulture);
        var authTicket = new FormsAuthenticationTicket(1, //version
                            userName, // user name
                            DateTime.Now,             //creation
                            DateTime.Now.AddMinutes(30), //Expiration
                            persistanceFlag, //Persistent
                            userData);

        var encTicket = FormsAuthentication.Encrypt(authTicket);
        Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
        return user;
    }

您的web.config中有这个吗?

<sessionState cookieless="AutoDetect" regenerateExpiredSessionId="true" timeout="20" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM