简体   繁体   English

在自定义角色和成员资格提供者中启用会话

[英]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. 我想在asp.net 4 no mvc中使用此项目

and use this code in web.config: 并在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" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何自定义会员提供者 - how to custom membership providers 自定义成员资格提供程序存在的问题 - Problems with custom membership providers C# - 表单身份验证代码 - 自定义角色和成员资格提供程序 - C# - Forms Authentication Code-Behind w Custom Role and Membership Providers 现有aspnet角色提供程序的自定义成员资格? - custom membership with existing aspnet Role provider? MVC 3应用程序中的自定义成员身份和角色提供程序 - Custom membership and role provider in MVC 3 application 自定义角色授权(无会员资格) - Custom role based authorization (without membership) 自定义MVC AuthorizeAttribute,允许多个角色成员身份 - Custom MVC AuthorizeAttribute that allows for multiple role membership 在3层设置中哪里可以找到自定义成员资格,角色,配置文件提供程序? - Where to locate custom membership, roles, profile providers in a 3-tier setup? 如何在自定义成员身份提供程序中保存ASP.NET_SessionId - how to save ASP.NET_SessionId in custom membership providers 帮助我决定是使用ASP.NET默认成员资格/角色提供程序还是编写自定义提供程序 - Help me decide whether to use ASP.NET default membership/roles providers or write custom providers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM