HttpContext.Current.Profile problem using Asp.net 2.0

Discussion in 'ASP .Net' started by Rodusa, Aug 30, 2005.

  1. Rodusa

    Rodusa Guest

    I am trying to replace cookies with the new "Asp.net 2.0 profiles" in
    my shopping cart application, but I am having trouble to access profile
    properties using HttpContext.Current.Profile. I can access any other
    property property of this class from a regular aspx page, but not from
    inside the class itself.

    This is the piece of the code that I am trying to get to work which can
    also be located at the bottom of the page, but so far just weariness.
    Any help at this point would be really appreciated.

    // WRITE TO PROFILE
    HttpContext.Current.Profile.CurrentBasketInfo.CartItems = dtSession;

    // MY WEB.CONFIG
    <profile defaultProvider="SqlProvider">
    <providers>
    <clear/>
    <add name="SqlProvider" type="System.Web.Profile.SqlProfileProvider"
    connectionStringName="myconnection" applicationName="/"
    description="SqlProfileProvider for SampleApplication"/>
    </providers>
    <properties>
    <add name="Name"/>
    <add name="SelectedShippingAddress" type="MyCart.Address"/>
    <add name="CurrentBasketInfo" type="MyCart.Basket"/>
    </properties>
    </profile>



    namespace MyCart
    {
    public class Basket: Product
    {

    private Address _ShippingAddress;
    public Address SelectedShippingAddress
    {
    get { return _ShippingAddress; }
    set { _ShippingAddress = value; }
    }

    private Contacts _ContactAddress;
    public Contacts ContactAddress
    {
    get { return _ContactAddress; }
    set { _ContactAddress = value; }
    }

    private string _CreditCardType;
    public string CreditCardType
    {
    get { return _CreditCardType; }
    set { _CreditCardType = value; }
    }

    private string _CreditCardNumber;
    public string CreditCardNumber
    {
    get { return _CreditCardNumber; }
    set { _CreditCardNumber = value; }
    }

    private string _CreditCardExpirationDate;
    public string CreditCardExpirationDate
    {
    get { return _CreditCardExpirationDate; }
    set { _CreditCardExpirationDate = value; }
    }

    private string _POnumber;
    public string POnumber
    {
    get { return _POnumber; }
    set { _POnumber = value; }
    }

    private string _BasketItems;
    public string BasketItems
    {
    get { return _BasketItems; }
    set { _BasketItems = value; }
    }

    private string _total;
    public string total
    {
    get { return _total; }
    set { _total = value; }
    }

    private DataTable _CartItems;
    public DataTable CartItems
    {
    get { return _CartItems; }
    set { _CartItems = value; }
    }


    public void AddItemToBasket(string item_sku, int qty)
    {
    // Checks new item Information in Database
    string sql = "select * from product where item_sku='" + item_sku + "'";
    SqlDataReader r = SqlServer.SearchSQL(sql, "myconnection");

    // Gets Current Basket Session DataTable
    DataTable dtSession = (DataTable)HttpContext.Current.Session["basket"];

    if (r.Read())
    {
    if (dtSession!=null) {
    DataView dv = new DataView(dtSession);
    dv.Sort = "item_sku";
    if (dv.Find(item_sku) == -1)
    {
    DataRow dr = dtSession.NewRow();
    dr["key"] = r["product_uid"].ToString();
    dr["item_sku"] = r["item_sku"].ToString();
    dr["short_desc"] = r["short_desc"].ToString();
    dr["qty"] = qty;
    dr["price"] = r["price"].ToString();
    dr["weight"] = r["weight"].ToString();
    dr["weight_unit"] = r["unit_uid"].ToString();
    dtSession.Rows.InsertAt(dr, 0);
    }

    // Writes Cookies
    WriteBasketCookies(dtSession); // b= basket cookie
    name
    // WRITE TO PROFILE
    HttpContext.Current.Profile.CurrentBasketInfo.CartItems =
    dtSession;
    }

    // Adds basket to DataTable Session Variable
    HttpContext.Current.Session["basket"] = dtSession;
    }

    }

    Thanks Rod
    Rodusa, Aug 30, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Newton
    Replies:
    0
    Views:
    2,892
    Mike Newton
    Jul 23, 2004
  2. Guest
    Replies:
    2
    Views:
    1,162
    Steven Cheng[MSFT]
    Aug 17, 2005
  3. Andy B
    Replies:
    0
    Views:
    519
    Andy B
    May 3, 2008
  4. Nicopilami
    Replies:
    2
    Views:
    630
    Nicopilami
    Mar 17, 2008
  5. Tony

    Dim context As HttpContext = HttpContext.Current

    Tony, Mar 2, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    307
    Teemu Keiski
    Mar 3, 2004
Loading...

Share This Page