【问题标题】:enable session in custom role and membership providers在自定义角色和成员提供者中启用会话
【发布时间】:2013-09-22 15:52:57
【问题描述】:

我有自定义角色和成员资格提供者。我想在 asp.net 4 no mvc 中使用这个Project。

并在 web.config 中使用此代码:

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

自定义成员资格提供程序和项目可以使用,但会话在项目中不可用。

我使用此代码登录:

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

【问题讨论】:

    标签: c# asp.net web-applications web-config


    【解决方案1】:

    你的 web.config 中有这个吗?

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

    【讨论】:

    • 我使用你的代码和 cookieless="UseCookies" 但不起作用。
    • 是的。但它不工作。我的自定义角色和成员资格提供程序的代码是否正确?:
    猜你喜欢
    • 1970-01-01
    • 2017-07-26
    • 1970-01-01
    • 1970-01-01
    • 2011-12-26
    • 2011-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多