在.NET成员资格中使用List类型的配置文件属性

han*_*ock 7 c# membership web-services asp.net-membership asp.net-profiles

我正在开发一个需要提供身份验证以及角色和配置文件管理的C#Webservice.我需要每个配置文件都有一个List类型的属性.web.config中的配置文件部分如下所示:

<profile defaultProvider="MyProfileProvider" enabled="true">
  <providers>
    <remove name="MyProfileProvider"/>
    <add connectionStringName="MySqlServer"
      applicationName="MyApp"
      name="MyProfileProvider"
      type="System.Web.Profile.SqlProfileProvider" />
  </providers>
  <properties>
    <add name="Websites" type="System.Collections.Generic.List&lt;String&gt;" serializeAs="Binary"/>
  </properties>
</profile> 
Run Code Online (Sandbox Code Playgroud)

但是,当我启动webservice并尝试访问该属性时,它返回以下错误:

System.Configuration.ConfigurationErrorsException:尝试加载此属性的类型导致以下错误:无法加载类型'System.Collections.Generic.List <String>'.(C:\ Projects\MyProject\web.config第58行)---> System.Web.HttpException:无法加载类型'System.Collections.Generic.List <String>'.

有没有办法为此目的使用通用集合?

han*_*ock 11

经过更多的搜索,我终于找到了答案.解决方案是使用由其命名空间限定的类型名称.这意味着我使用的问题:

<add name="Websites" type="System.Collections.Generic.List`1[System.String]" serializeAs="Binary"/>
Run Code Online (Sandbox Code Playgroud)

我还发现也可以指定其他程序集中定义的类.要使用那些,您需要程序集限定名称.例如,那将是"System.Collections.Generic.HashSet`1 [[System.String,mscorlib,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089]],System.Core,Version = 3.5.0.0,对于Hashset of Strings,Culture = neutral,PublicKeyToken = b77a5c561934e089.