| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦   
共有 592 人关注过本帖
标题:web.config中定义profile之后为什么不能引用?
收藏  订阅  推荐  打印
sgzhaohang
Rank: 1
等级:新手上路
帖子:7
积分:216
注册:2008-7-11
web.config中定义profile之后为什么不能引用?

web.config中
<system.web>
        <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.
        -->
      <profile>
        <properties>
          <add name ="Country"/>
          <add name ="Visits" type ="System.Int32" defaultValue ="0"/>
          <add name ="LastVisit" type ="System.DateTime"/>
        </properties>
      </profile>

在另一个webform中
LabelLastVisit.Text = Profile.LastVisit.ToLongTimeString();
            LabelVisitCount.Text = Profile.Visits.ToString();
            LabelSelectedCountry.Text = Profile.Country;
            
            Profile.Visits++;
            Profile.LastVisit = DateTime.Now;

就说 The name 'Profile' does not exist in the current context
2008-7-27 22:37
青格儿
Rank: 4
等级:高级会员
威望:2
帖子:516
积分:6134
注册:2007-7-31

你确定你配置的webconfig对了吗?你配置没配全,指定数据库了吗?而且配置后还要为你指定的数据库添加"以支持用户配置文件功能"。否则即使找到了Profile,你的页面也不能正常运行起来。
2008-7-29 14:44
sgzhaohang
Rank: 1
等级:新手上路
帖子:7
积分:216
注册:2008-7-11
回复 2# 青格儿 的帖子

楼上的大哥能详细说一下吗?我新手不太懂!这是我web.config内容
<?xml version="1.0"?>

<configuration>


    <configSections>
      <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
          <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
            <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
            <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
            <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
          </sectionGroup>
        </sectionGroup>
      </sectionGroup>
    </configSections>  

  
    <appSettings/>
    <connectionStrings/>
  
    <system.web>
        <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.
        -->
      <profile>
        <properties>
          <add name ="Country"/>
          <add name ="Visits" type ="System.Int32" defaultValue ="0"/>
          <add name ="LastVisit" type ="System.DateTime"/>
        </properties>
      </profile>
      
      <compilation debug="false">

        <assemblies>
            <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          </assemblies>

        </compilation>
        <!--
            The <authentication> section enables configuration
            of the security authentication mode used by
            ASP.NET to identify an incoming user.
        -->
        <authentication mode="Forms" />
        <!--
            The <customErrors> section enables configuration
            of what to do if/when an unhandled error occurs
            during the execution of a request. Specifically,
            it enables developers to configure html error pages
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->

      <pages>
        <controls>
          <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </controls>
      </pages>

      <httpHandlers>
        <remove verb="*" path="*.asmx"/>
        <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
      </httpHandlers>
      <httpModules>
        <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </httpModules>
   
    </system.web>

    <system.codedom>
      <compilers>
        <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
                  type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <providerOption name="CompilerVersion" value="v3.5"/>
          <providerOption name="WarnAsError" value="false"/>
        </compiler>
     </compilers>
    </system.codedom>
   
    <!--
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    -->
    <system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>
      <modules>
        <remove name="ScriptModule" />
        <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </modules>
      <handlers>
        <remove name="WebServiceHandlerFactory-Integrated"/>
        <remove name="ScriptHandlerFactory" />
        <remove name="ScriptHandlerFactoryAppServices" />
        <remove name="ScriptResource" />
        <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
             type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"
             type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </handlers>
    </system.webServer>

    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
          <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
          <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
        </dependentAssembly>
      </assemblyBinding>
    </runtime>

</configuration>
2008-7-29 19:11
hebingbing
Rank: 12Rank: 12Rank: 12
来自:泰山学院
等级:版主
威望:10
帖子:3032
积分:32164
注册:2007-10-22

她可不是大哥啊……
是大姐啊,呵呵
要用这个要加上命名空间System.Web.Profile 的,这个命名空间是2.0新增加的,所以可能很多的数、书籍上都不怎么讲这个东西

【www.bcsnjd.cn】编程少年基地:提供在线视频教程、电子图书、程序源码等众多资源,欢迎访问
本人免费做asp.net,c#,asp,vb等毕业设计。要求想法极具创新QQ:491131231
2008-7-29 22:32
青格儿
Rank: 4
等级:高级会员
威望:2
帖子:516
积分:6134
注册:2007-7-31

呵呵,大哥,大姐没关系,只是个称呼而已。
在System.web 下添加
<authentication mode="Forms" />

    <anonymousIdentification enabled="true" />

      <profile enabled="true" automaticSaveEnabled="true" defaultProvider="SqlProvider">
        <providers>
          <clear />
          <add name="SqlProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="你的连接数据库字符串名"  applicationName="ProfileSample"  description="Sample for ASP.NET profile and Profile Service" />
        </providers>
        <properties>
        <add
        name="FirstName"  
        defaultValue="Bill"
        allowAnonymous="true" />
        <add
          name="LastName"
          defaultValue="Smith"
          allowAnonymous="true" />
        <add
          name="PageVisits"
          type="Int32"
          allowAnonymous="true"/>
      </properties>
    </profile>
然后,在VS2005命令提示里给你的数据库添加profile支持:
aspnet_regsql -E -S <ServerName> -A p -d <DatabaseName>

然后在后台写你需要的代码,就可以了。
2008-7-30 19:06
sgzhaohang
Rank: 1
等级:新手上路
帖子:7
积分:216
注册:2008-7-11

多谢楼上的大哥大姐啦:)
2008-7-30 22:51
共有 591 人关注过本帖
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.094613 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved