R
Rodusa
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
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