我需要从web.config文件中获取所有配置文件属性
<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>
我希望数组中包含值[&#39; FirstName&#39;,&#39; LastName&#39;,&#39;公司&#39;]
答案 0 :(得分:1)
这应该是你的数组:
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
有关ProfileSection的更多信息:https://msdn.microsoft.com/en-us/library/system.web.configuration.profilesection(v=vs.100).aspx