Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 应用程序连接多个数据库并设置成员资格cookie_C#_Asp.net_Asp.net Mvc_Web Config_Asp.net Membership - Fatal编程技术网

C# 应用程序连接多个数据库并设置成员资格cookie

C# 应用程序连接多个数据库并设置成员资格cookie,c#,asp.net,asp.net-mvc,web-config,asp.net-membership,C#,Asp.net,Asp.net Mvc,Web Config,Asp.net Membership,我正在编写一个方法,用它设置所有数据库连接字符串。该方法有一些参数,如连接字符串和cookie域(对于单点登录状态) 我可以使用作为参数发送的指定连接字符串获取成员资格和角色信息 //membership System.Web.Security.SqlMembershipProvider mp = new System.Web.Security.SqlMembershipProvider(); System.Collecti

我正在编写一个方法,用它设置所有数据库连接字符串。该方法有一些参数,如连接字符串和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信息

我发现以下代码:

            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();


            }