protected void Page_Load(object sender, EventArgs e) { string rawId = Request.QueryString["productID"]; Session["productId"] = rawId; //Session["Error"] = rawId; //Response.Redirect("/UserPages/ErrorPage.aspx"); int productId; if (!String.IsNullOrEmpty(rawId) && int.TryParse(rawId, out productId)) { using (ShoppingCartEngine usersShoppingCart = new ShoppingCartEngine()) { usersShoppingCart.AddToCart(Convert.ToInt16(rawId)); //remove 1 unit from inventory // cartEngine.DiminishInventory(); } } else { Debug.Fail("ERROR : accessing AddToCart.aspx without a ProductId."); throw new Exception("ERROR : illegal action accessing AddToCart.aspx without ProductId."); } Response.Redirect("ShoppingCart.aspx"); }