scope in web application - global.asax
Posted on 2007-04-07
I am building a simple shopping cart applicaiton. A single products page shows items in a row that contains an 'add' button which starts the process in code behind (.aspx.cs) C# code
I have a global.asax file in which I declare a session object to store the shopping cart items in an encrypted string called ‘cart’. This object is built in the session_start event of global.asax. Also in that file is a public class CartItem with a constructor for the details [in each row of the product catalog].
What I don’t understand is how to call this method CartItem from an aspx.cs file. In the code behind [.aspx.cs] is the _ItemCommand event where I have this line
List<int, CartItem> cart = (Session["cart"] as List<int, CartItem>);
I get an ‘out of context’ error for CartItem. This looks like a scope issue to me. I imagine that the global.asax file is in fact global to the application and that its public methods should be visible from other files. What am I missing?
Thanks for any advice,