Reading membership section from web.config

前端 未结 3 1175
再見小時候
再見小時候 2021-01-12 23:52

I have created a custom MembershipProvider class, so far so good, however, I am not sure how to read the configuration settings from the web.config file.

I tried to

3条回答
  •  太阳男子
    2021-01-13 00:39

    here is the solution in code :

            MembershipSection membershipSection = (MembershipSection)WebConfigurationManager.GetSection("system.web/membership");
            string defaultProvider = membershipSection.DefaultProvider;
            ProviderSettings providerSettings = membershipSection.Providers[defaultProvider];
            string connectionStringName = providerSettings.Parameters["connectionStringName"];
            string connectionUsername = providerSettings.Parameters["connectionUsername"];
            string connectionPassword = providerSettings.Parameters["connectionPassword"];
            string connectionString = WebConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
    

提交回复
热议问题