获取从web配置配置文件属性名称
问题描述:
我需要从web.config文件中的所有配置文件属性获取从web配置配置文件属性名称
<profile defaultProvider="AspNetSqlProfileProvider" automaticSaveEnabled="false" enabled="true">
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
<properties>
<add name="FirstName" type="string" />
<add name="LastName" type="string" />
<add name="Company" type="string" />
</properties>
我想与值[“名字”,“姓氏数组”, '公司']
答
这应该让你的数组:上ProfileSection
var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/aspnet");
var profileSection = (System.Web.Configuration.ProfileSection)configuration.GetSection("system.web/profile");
var properties = profileSection.PropertySettings.AllKeys; //FirstName, LastName, Company
的更多信息:https://msdn.microsoft.com/en-us/library/system.web.configuration.profilesection(v=vs.100).aspx
谢谢你。这就是我想要的。 – Lucifer