当前上下文中不存在名称“Profile,如何解决?

error CS0103: 当前上下文中不存在名称“Profile”

img

但是在web.config文件已经定义了profile

<configuration>
  <connectionStrings>
    <add name="MyPetShopConnectionString" connectionString="Data Source=(localdb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\MyPetShop.mdf;Initial Catalog=MyPetShop;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
    <system.web>
        <compilation debug="true" targetFramework="4.0">
            <assemblies>
                <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            </assemblies>
        </compilation>
        <anonymousIdentification enabled="true" />
        <profile>
            <properties>
                <group name="Cart">
                    <add name="ProId" type="System.Collections.ArrayList" allowAnonymous="true" />
                    <add name="Proname" type="System.Collections.ArrayList" allowAnonymous="true" />
                    <add name="Qty" type="System.Collections.ArrayList" allowAnonymous="true" />
                    <add name="ListPrice" type="System.Collections.ArrayList" allowAnonymous="true" />
                    <add name="TotalPrice" allowAnonymous="true" />
                    </group>
                </properties>
            </profile>
                </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
</configuration>

你试试这个呢:

List<String> lists = (List<String>)HttpContext.Current.Profile.GetProfileGroup("Cart").GetPropertyValue("ProName");

这里有一篇不错的博客,你可以简单参考: