一个应用程序连接多个数据库并设置会员cookie

An Application Connect with Multiple database and set Membership cookies

我正在编写一个方法来设置所有数据库连接字符串 it.The 方法有一些参数,如连接字符串和 cookie 域(用于单点登录状态),...

我可以使用作为参数发送的指定连接字符串获取成员资格和角色信息。

            //membership
            System.Web.Security.SqlMembershipProvider mp = new System.Web.Security.SqlMembershipProvider();
            System.Collections.Specialized.NameValueCollection config_Membership = new System.Collections.Specialized.NameValueCollection();
            config_Membership.Add("connectionString", connectionstring);
            config_Membership.Add("applicationName", "/");
            mp.Initialize("SQL_test_Membership", config_Membership);
            var u = mp.GetUser(username, false);
            int TotalRecords = 0;
            var p = mp.GetAllUsers(0, 1, out TotalRecords);

           //login
            bool valid = mp.ValidateUser(username, password);

            System.Web.Security.SqlRoleProvider rp = new System.Web.Security.SqlRoleProvider();
            System.Collections.Specialized.NameValueCollection config_Role = new System.Collections.Specialized.NameValueCollection();
            config_Role.Add("connectionString", connectionstring);
            config_Role.Add("applicationName", "/");
            rp.Initialize("SQL_test_Role", config_Role);
            var roles = rp.GetRolesForUser(username);

我想像上面的代码一样获取 ProfileBase 信息

https://technet.microsoft.com/nl-nl/library/system.web.profile.profilebase.initialize(v=vs.85).aspx

我发现下面的代码:

            System.Web.Profile.ProfileBase pro = new System.Web.Profile.ProfileBase();
            System.Collections.Specialized.NameValueCollection config_profile = new System.Collections.Specialized.NameValueCollection();
            config_profile.Add("connectionString", connectionstring);
            config_profile.Add("applicationName", "/");
            pro.Initialize(?????)

但是我不知道如何将参数发送到pro.Initialize(),有人可以帮我吗?谢谢

我的问题解决了。我的代码已更改:

            //login
            bool valid = mp.ValidateUser(username, password);

            if (valid)
            {
                System.Web.Profile.ProfileBase pro = new System.Web.Profile.ProfileBase();
                System.Collections.Specialized.NameValueCollection config_profile = new System.Collections.Specialized.NameValueCollection();
                config_profile.Add("connectionString", connectionstring);
                config_profile.Add("applicationName", "/");
                pro.Initialize(username, true);


                string Name = pro.GetPropertyValue("Name").ToString();
                string Family = pro.GetPropertyValue("Family").ToString();
                string phone = pro.GetPropertyValue("Phone").ToString();
                string address = pro.GetPropertyValue("Address").ToString();


            }