HttpContext, HttpContextBase and Httpcontxtwrapper

Source: Internet
Author: User
HttpContext

The HttpContext is a context object in ASP. But the problem with this class is that it has no base class and is not a virtual function. This way, we can't mock it when we write the unit test. Therefore, it is advisable not to pass HttpContext as a parameter, but instead to use HttpContextBase instead.

HttpContextBase

This is a new feature in C # 3.5 that replaces HttpContext. Since the class is an abstract class, it can be mock.

Httpcontextwrapper

This class is also introduced in the c#3.5. It is the concrete realization of httpcontextbase. Create a httpcontextwrapper in a webpage, you can do this

New Httpcontextwrapper (httpcontext.current) as HttpContextBase

Reference:

http://www.splinter.com.au/httpcontext-vs-httpcontextbase-vs-httpcontext/

HttpContext, HttpContextBase and Httpcontxtwrapper

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.