| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3417 人关注过本帖, 1 人收藏
标题:web.config中定义profile之后为什么不能引用?
只看楼主 加入收藏
sgzhaohang
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-7-11
收藏(1)
 问题点数:0 回复次数:5 
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
搜索更多相关主题的帖子: web profile config 定义 
2008-07-27 22:37
青格儿
Rank: 4
等 级:贵宾
威 望:11
帖 子:698
专家分:20
注 册:2007-7-31
收藏
得分:0 
你确定你配置的webconfig对了吗?你配置没配全,指定数据库了吗?而且配置后还要为你指定的数据库添加"以支持用户配置文件功能"。否则即使找到了Profile,你的页面也不能正常运行起来。
2008-07-29 14:44
sgzhaohang
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-7-11
收藏
得分:0 
回复 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
             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 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-07-29 19:11
hebingbing
Rank: 6Rank: 6
来 自:黄土高坡
等 级:贵宾
威 望:27
帖 子:3417
专家分:371
注 册:2007-10-22
收藏
得分:0 
她可不是大哥啊……
是大姐啊,呵呵
要用这个要加上命名空间System.Web.Profile 的,这个命名空间是2.0新增加的,所以可能很多的数、书籍上都不怎么讲这个东西
2008-07-29 22:32
青格儿
Rank: 4
等 级:贵宾
威 望:11
帖 子:698
专家分:20
注 册:2007-7-31
收藏
得分:0 
呵呵,大哥,大姐没关系,只是个称呼而已。
在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 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-07-30 19:06
sgzhaohang
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-7-11
收藏
得分:0 
多谢楼上的大哥大姐啦:)
2008-07-30 22:51
快速回复:web.config中定义profile之后为什么不能引用?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017040 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved