+ -
当前位置:首页 → 问答吧 → “HttpContext.Current.Profile”引发Configuration.ConfigurationErrorsException类型的异常

“HttpContext.Current.Profile”引发Configuration.ConfigurationErrorsException类型的异常

时间:2011-12-25

来源:互联网


以下是Web.config代码:
C# code

      <profile enabled="true" inherits="Web.MyProfileCommon">
        <properties>
          <add name="UserName" allowAnonymous="false" type="string" />
          <add name="ShoppingCart" allowAnonymous="false" type="BLL.CartManager"/>//这行是72行
        </properties>
      </profile>




下面是我自己写的Web.MyProfileCommon类(用的是Web application):
C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Profile;
using BLL;

namespace Web
{
    public class MyProfileCommon : System.Web.Profile.ProfileBase
    {
        public MyProfileCommon() //无参构造函数
        { }

        [SettingsAllowAnonymous(false)]
        public string UserName
        {
            get { return base["UserName"].ToString(); }
            set { base["UserName"] = value; }
        }

        [SettingsAllowAnonymous(false)]
        public CartManager ShoppingCart
        {
            get { return (CartManager)base["ShoppingCart"]; }
            set { base["ShoppingCart"] = value; }
        }

    }
}



我在code-behind里面这里写了一个全局定义:
C# code

 public partial class ShoppingCart : System.Web.UI.Page
    {
        MyProfileCommon Profile = (MyProfileCommon)HttpContext.Current.Profile;//这样定义了一个Profile

        protected void Page_Load(object sender, EventArgs e)
        {



然后调试的时候出错了,Profile为null,(未将对象引用设置到对象的实例)
错误信息:
HttpContext.Current.Profile “HttpContext.Current.Profile”引发了“System.Configuration.ConfigurationErrorsException”类型的异常 System.Web.Profile.ProfileBase {System.Configuration.ConfigurationErrorsException}

base: {"已定义此配置文件属性。 (F:\\网上购物系统\\StarBookShop\\Web\\web.config line 72)"} System.Exception {System.Configuration.ConfigurationErrorsException}

请高手指点迷津啊。。小弟刚学用Profile保存信息,现在被问题卡住了,找不到办法解决,求帮助!

作者: q380472335   发布时间: 2011-12-25

顶啊顶啊..求帮助

作者: q380472335   发布时间: 2011-12-25