Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > BOOK: Professional ASP.NET Design Patterns
|
BOOK: Professional ASP.NET Design Patterns
This is the forum to discuss the Wrox book Professional ASP.NET Design Patterns by Scott Millett; ISBN: 978-0-470-29278-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET Design Patterns section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 26th, 2012, 11:31 AM
Registered User
 
Join Date: Apr 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Stuck on chapter 2: HttpContext in a class library

As instructed by the book, I have included the reference to System.Web in the directives of my ProductService class:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace ASPPatterns.Chap2.Service
{
    public class ProductService
    {
        private ProductRepository _productRepository;

        public ProductService()
        {
            _productRepository = new ProductRepository();
        }

        public IList<Product> GetAllProductsIn(int categoryId)
        {
            IList<Product> products;
            string storageKey = string.Format("products_in_category_id_{0}", categoryId);

            products = (List<Product>)System.Web.HttpContext.Current.Cache.Get(storageKey);

            if (products == null)
            {
                products = _productRepository.GetAllProductsIn(categoryId);
                HttpContext.Current.Cache.Insert(storageKey, products);
            }
        }
    }
}
But the errors I'm getting are:

Code:
Error	1	The type or namespace name 'HttpContext' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
and

Code:
Error	2	The name 'HttpContext' does not exist in the current context
Can anyone explain how I'm supposed to get the HttpContext class to work inside of a class library?

Thanks!
 
Old April 26th, 2012, 11:52 AM
elbandit's Avatar
Wrox Author
 
Join Date: May 2007
Posts: 107
Thanks: 10
Thanked 17 Times in 15 Posts
Default

Hi sethxdeath,

Thanks for buying the book!

You will need to add a reference to the System.Web assembly. Right click on the project and 'Add Reference...', select the .Net tab and then add System.Web from the list.

Cheers
Scott
 
Old April 26th, 2012, 12:04 PM
Registered User
 
Join Date: Apr 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh, boy, how embarrassingly silly of me. Thanks so much hahaha





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 10 minor issue with the Class library notig BOOK: Beginning Visual C# 2010 0 September 26th, 2010 09:56 PM
use of class library Theone84 C# 1 July 26th, 2008 02:19 AM
Advanced Help! Object Class Programming! I'm stuck gingerj Javascript How-To 0 September 4th, 2006 02:55 PM
Regarding Class Library (.dll) from class file manish.sharma04 BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 March 3rd, 2006 07:32 AM
Class Library ~Bean~ ASP.NET 1.x and 2.0 Application Design 3 October 17th, 2005 07:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.