?????????“???????????????Щ?????????????????????”???α??????????????????????????????????????????????????????????д???????????????????Щ?????????????????????????????????裺

????1???????д???????????????????????????????????????????????????????Virtual?????

????2?????????????????e????????????????????д????????

???????????????????????????????????????????WebForm??UI?????????????д?????????????????????WebForm?????????У???Response????????Response?????

namespace System.Web
{
    public sealed class HttpResponse
    {
        ...
    }
}

???????????????????????WebForm?????????У??????????????

protected void Page_Load(object sender?? EvengArgs e)
{
  this.Response.Write("test u");
}

?????ú???????????????е????????????????MOQ?????????????????????п????д?У????????????????????????????????????滻???????

?????????д?????????????????????Responseд???????????HttpResponseWrapper??

View Code

namespace System.Web
{
    [TypeForwardedFrom("System.Web.Abstractions?? Version=3.5.0.0?? Culture=Neutral?? PublicKeyToken=31bf3856ad364e35")]
    public class HttpResponseWrapper : HttpResponseBase
    {
        public override bool Buffer
        {
            get
            {
            }
            set
            {
            }
        }
        public override bool BufferOutput
        {
            get
            {
            }
            set
            {
            }
        }
        public override HttpCachePolicyBase Cache
        {
            get
            {
            }
        }
        public override string CacheControl
        {
            get
            {
            }
            set
            {
            }
        }
        public override string Charset
        {
            get
            {
            }
            set
            {
            }
        }
        public override CancellationToken ClientDisconnectedToken
        {
            get
            {
            }
        }
        public override Encoding ContentEncoding
        {
            get
            {
            }
            set
            {
            }
        }
        public override string ContentType
        {
            get
            {
            }
            set
            {
            }
        }
        public override HttpCookieCollection Cookies
        {
            get
            {
            }
        }
        public override int Expires
        {
            get
            {
            }
            set
            {
            }
        }
        public override DateTime ExpiresAbsolute
        {
            get
            {
            }
            set
            {
            }
        }
        public override Stream Filter
        {
            get
            {
            }
            set
            {
            }
        }
        public override NameValueCollection Headers
        {
            get
            {
            }
        }
        public override Encoding HeaderEncoding
        {
            get
            {
            }
            set
            {
            }
        }
        public override bool IsClientConnected
        {
            get
            {
            }
        }
        public override bool IsRequestBeingRedirected
        {
            get
            {
            }
        }
        public override TextWriter Output
        {
            get
            {
            }
            set
            {
            }
        }
        public override Stream OutputStream
        {
            get
            {
            }
        }
        public override string RedirectLocation
        {
            get
            {
            }
            set
            {
            }
        }
        public override string Status
        {
            get
            {
            }
            set
            {
            }
        }
        public override int StatusCode
        {
            get
            {
            }
            set
            {
            }
        }
        public override string StatusDescription
        {
            get
            {
            }
            set
            {
            }
        }
        public override int SubStatusCode
        {
            get
            {
            }
            set
            {
            }
        }
        public override bool SupportsAsyncFlush
        {
            get
            {
            }
        }
        public override bool SuppressContent
        {
            get
            {
            }
            set
            {
            }
        }
        public override bool SuppressFormsAuthenticationRedirect
        {
            get
            {
            }
            set
            {
            }
        }
        public override bool TrySkipIisCustomErrors
        {
            get
            {
            }
            set
            {
            }
        }
        public HttpResponseWrapper(HttpResponse httpResponse)
        {
        }
        public override void AddCacheItemDependency(string cacheKey)
        {
        }
        public override void AddCacheItemDependencies(ArrayList cacheKeys)
        {
        }
        public override void AddCacheItemDependencies(string[] cacheKeys)
        {
        }
        public override void AddCacheDependency(params CacheDependency[] dependencies)
        {
        }
        public override void AddFileDependency(string filename)
        {
        }
        public override void AddFileDependencies(ArrayList filenames)
        {
        }
        public override void AddFileDependencies(string[] filenames)
        {
        }
        public override void AddHeader(string name?? string value)
        {
        }
        public override void AppendCookie(HttpCookie cookie)
        {
        }
        public override void AppendHeader(string name?? string value)
        {
        }
        public override void AppendToLog(string param)
        {
        }
        public override string ApplyAppPathModifier(string virtualPath)
        {
        }
        public override IAsyncResult BeginFlush(AsyncCallback callback?? object state)
        {
        }
        public override void BinaryWrite(byte[] buffer)
        {
        }
        public override void Clear()
        {
        }
        public override void ClearContent()
        {
        }
        public override void ClearHeaders()
        {
        }
        public override void Close()
        {
        }
        public override void DisableKernelCache()
        {
        }
        public override void DisableUserCache()
        {
        }
        public override void End()
        {
        }
        public override void EndFlush(IAsyncResult asyncResult)
        {
        }
        public override void Flush()
        {
        }
        public override void Pics(string value)
        {
        }
        public override void Redirect(string url)
        {
        }
        public override void Redirect(string url?? bool endResponse)
        {
        }
        public override void RedirectPermanent(string url)
        {
        }
        public override void RedirectPermanent(string url?? bool endResponse)
        {
        }
        public override void RedirectToRoute(object routeValues)
        {
        }
        public override void RedirectToRoute(string routeName)
        {
        }
        public override void RedirectToRoute(RouteValueDictionary routeValues)
        {
        }
        public override void RedirectToRoute(string routeName?? object routeValues)
        {
        }
        public override void RedirectToRoute(string routeName?? RouteValueDictionary routeValues)
        {
        }
        public override void RedirectToRoutePermanent(object routeValues)
        {
        }
        public override void RedirectToRoutePermanent(string routeName)
        {
        }
        public override void RedirectToRoutePermanent(RouteValueDictionary routeValues)
        {
        }
        public override void RedirectToRoutePermanent(string routeName?? object routeValues)
        {
        }
        public override void RedirectToRoutePermanent(string routeName?? RouteValueDictionary routeValues)
        {
        }
        public override void RemoveOutputCacheItem(string path)
        {
        }
        public override void RemoveOutputCacheItem(string path?? string providerName)
        {
        }
        public override void SetCookie(HttpCookie cookie)
        {
        }
        public override void TransmitFile(string filename)
        {
        }
        public override void TransmitFile(string filename?? long offset?? long length)
        {
        }
        public override void Write(string s)
        {
        }
        public override void Write(char ch)
        {
        }
        public override void Write(char[] buffer?? int index?? int count)
        {
        }
        public override void Write(object obj)
        {
        }
        public override void WriteFile(string filename)
        {
        }
        public override void WriteFile(string filename?? bool readIntoMemory)
        {
        }
        public override void WriteFile(string filename?? long offset?? long size)
        {
        }
        public override void WriteFile(IntPtr fileHandle?? long offset?? long size)
        {
        }
        public override void WriteSubstitution(HttpResponseSubstitutionCallback callback)
        {
        }
    }
}

????????????????????????????????????????????????????????????????????????????HttpResponseBase??У????????????????????????????д???

protected HttpResponseBase _response;

protected void Page_Load(object sender?? EvengArgs e)
{
  _response.Write("test u");
}

????OK?????????????????????????????????????_response???

??????????????д??????????y?????????????????????????????????????????????virtual????????

??????????????????Щ????????????????????汾?????????????????????????????????????滻???????DLL??????????????????????????????????????e??????????????????????????????

?????????????http://www.cnblogs.com/luminji/archive/2012/12/31/2840455.html