<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

        HttpResponse的Output與OutputStream、Filter關(guān)系與區(qū)別介紹

        來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 22:42:08
        文檔

        HttpResponse的Output與OutputStream、Filter關(guān)系與區(qū)別介紹

        HttpResponse的Output與OutputStream、Filter關(guān)系與區(qū)別介紹:在網(wǎng)上經(jīng)常看見有這樣的代碼 HttpResponse response = HttpContext.Current.Response; response.Filter = new PageFilter(response.Filter); 來(lái)攔截輸出流,自己也做個(gè)類似的東東,如asp.net中 js 合并 壓縮,現(xiàn)在我也來(lái)說(shuō)說(shuō)這幾個(gè)東東是什么吧,
        推薦度:
        導(dǎo)讀HttpResponse的Output與OutputStream、Filter關(guān)系與區(qū)別介紹:在網(wǎng)上經(jīng)常看見有這樣的代碼 HttpResponse response = HttpContext.Current.Response; response.Filter = new PageFilter(response.Filter); 來(lái)攔截輸出流,自己也做個(gè)類似的東東,如asp.net中 js 合并 壓縮,現(xiàn)在我也來(lái)說(shuō)說(shuō)這幾個(gè)東東是什么吧,

        在網(wǎng)上經(jīng)常看見有這樣的代碼

        HttpResponse response = HttpContext.Current.Response;
        response.Filter = new PageFilter(response.Filter);

        來(lái)攔截輸出流,自己也做個(gè)類似的東東,如asp.net中 js 合并 壓縮,現(xiàn)在我也來(lái)說(shuō)說(shuō)這幾個(gè)東東是什么吧,需要大家對(duì)asp.net的生命周期比較熟悉,如不熟悉的朋友建議先看看ASP.NET 請(qǐng)求處理流程 ASP.NET管線與應(yīng)用程序生命周期

        首先我們來(lái)看看這3個(gè)屬性的源代碼吧:

        代碼如下:
        public TextWriter Output
        {
        get
        {
        return this._writer;
        }
        set
        {
        this._writer = value;
        }
        }


        public Stream OutputStream
        {
        get
        {
        if (!this.UsingHttpWriter)
        {
        throw new HttpException(SR.GetString("OutputStream_NotAvail"));
        }
        return this._httpWriter.OutputStream;
        }
        }


        代碼如下:
        public Stream Filter
        {
        get
        {
        if (this.UsingHttpWriter)
        {
        return this._httpWriter.GetCurrentFilter();
        }
        return null;
        }
        set
        {
        if (!this.UsingHttpWriter)
        {
        throw new HttpException(SR.GetString("Filtering_not_allowed"));
        }
        this._httpWriter.InstallFilter(value);
        IIS7WorkerRequest request = this._wr as IIS7WorkerRequest;
        if (request != null)
        {
        request.ResponseFilterInstalled();
        }
        }
        }

        我們看到Filter和OutputStream都用到了一個(gè)屬性UsingHttpWriter,那這個(gè)屬性是怎么定義的了
        代碼如下:
        private bool UsingHttpWriter
        {
        get
        {
        return ((this._httpWriter != null) && (this._writer == this._httpWriter));
        }
        }

        從這個(gè)屬性我們可以知道_writer 、_httpWriter實(shí)際上是同一個(gè)東東,它們的類型是HttpWriter ,而HttpWriter 又繼承與TextWriter。現(xiàn)在我們可以解釋Output就是_httpWriter,而OutputStream是_httpWriter的OutputStream屬性。類HttpWriter 主要代碼如下
        代碼如下:
        public Stream OutputStream
        {
        get
        {
        return this._stream;
        }
        }


        internal HttpWriter(HttpResponse response) : base(null)
        {
        this._response = response;
        this._stream = new HttpResponseStream(this);
        this._buffers = new ArrayList();
        this._lastBuffer = null;
        this._charBuffer = (char[]) s_Allocator.GetBuffer();
        this._charBufferLength = this._charBuffer.Length;
        this._charBufferFree = this._charBufferLength;
        this.UpdateResponseBuffering();
        }


        internal HttpResponseStream(HttpWriter writer)
        {
        this._writer = writer;
        }

        HttpResponse 在Filter屬性設(shè)置調(diào)用了HttpWriter類的InstallFilter方法,而獲取調(diào)用了該類的GetCurrentFilter
        代碼如下:
        internal void InstallFilter(Stream filter)
        {
        if (this._filterSink == null)
        {
        throw new HttpException(SR.GetString("Invalid_response_filter"));
        }
        this._installedFilter = filter;
        }

        internal Stream GetCurrentFilter()
        {
        if (this._installedFilter != null)
        {
        return this._installedFilter;
        }
        if (this._filterSink == null)
        {
        this._filterSink = new HttpResponseStreamFilterSink(this);
        }
        return this._filterSink;
        }

        由以上代碼我們可以得知HttpResponse的輸出流就是Filter屬性設(shè)置的流,即HttpResponse的Output和OutputStream屬性的輸出流都是來(lái)自Filter中的流。我們來(lái)看看_writer 、_httpWriter它們是在什么時(shí)候初始化的了?在HttpResonse中有一個(gè)方法
        代碼如下:
        internal void InitResponseWriter()
        {
        if (this._httpWriter == null)
        {
        this._httpWriter = new HttpWriter(this);
        this._writer = this._httpWriter;
        }
        }

        該方法是由HttpRuntime的ProcessRequestInternal來(lái)調(diào)用
        代碼如下:
        private void ProcessRequestInternal(HttpWorkerRequest wr)
        {
        HttpContext context;
        try
        {
        context = new HttpContext(wr, false);
        }
        catch
        {
        wr.SendStatus(400, "Bad Request");
        wr.SendKnownResponseHeader(12, "text/html; charset=utf-8");
        byte[] bytes = Encoding.ASCII.GetBytes("<html><body>Bad Request</body></html>");
        wr.SendResponseFromMemory(bytes, bytes.Length);
        wr.FlushResponse(true);
        wr.EndOfRequest();
        return;
        }
        wr.SetEndOfSendNotification(this._asyncEndOfSendCallback, context);
        Interlocked.Increment(ref this._activeRequestCount);
        HostingEnvironment.IncrementBusyCount();
        try
        {
        try
        {
        this.EnsureFirstRequestInit(context);
        }
        catch
        {
        if (!context.Request.IsDebuggingRequest)
        {
        throw;
        }
        }
        context.Response.InitResponseWriter();
        IHttpHandler applicationInstance = HttpApplicationFactory.GetApplicationInstance(context);
        if (applicationInstance == null)
        {
        throw new HttpException(SR.GetString("Unable_create_app_object"));
        }
        if (EtwTrace.IsTraceEnabled(5, 1))
        {
        EtwTrace.Trace(EtwTraceType.ETW_TYPE_START_HANDLER, context.WorkerRequest, applicationInstance.GetType().FullName, "Start");
        }
        if (applicationInstance is IHttpAsyncHandler)
        {
        IHttpAsyncHandler handler2 = (IHttpAsyncHandler) applicationInstance;
        context.AsyncAppHandler = handler2;
        handler2.BeginProcessRequest(context, this._handlerCompletionCallback, context);
        }
        else
        {
        applicationInstance.ProcessRequest(context);
        this.FinishRequest(context.WorkerRequest, context, null);
        }
        }
        catch (Exception exception)
        {
        context.Response.InitResponseWriter();
        this.FinishRequest(wr, context, exception);
        }
        }

        聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        HttpResponse的Output與OutputStream、Filter關(guān)系與區(qū)別介紹

        HttpResponse的Output與OutputStream、Filter關(guān)系與區(qū)別介紹:在網(wǎng)上經(jīng)常看見有這樣的代碼 HttpResponse response = HttpContext.Current.Response; response.Filter = new PageFilter(response.Filter); 來(lái)攔截輸出流,自己也做個(gè)類似的東東,如asp.net中 js 合并 壓縮,現(xiàn)在我也來(lái)說(shuō)說(shuō)這幾個(gè)東東是什么吧,
        推薦度:
        標(biāo)簽: http htt filter
        • 熱門焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: h在线观看视频免费网站| 麻豆成人精品国产免费| 18禁美女裸体免费网站| 四虎成人免费大片在线| 亚洲无人区一区二区三区| 特级aaaaaaaaa毛片免费视频| 99免费精品视频| 国产AV无码专区亚洲AWWW| 岛国岛国免费V片在线观看 | 毛片a级毛片免费播放下载 | 亚洲狠狠婷婷综合久久久久| 在线a亚洲老鸭窝天堂av高清| 一级午夜免费视频| 久久久久久国产精品免费免费| 99久久婷婷国产综合亚洲| 毛片A级毛片免费播放| 亚洲精华液一二三产区| 国产在线a不卡免费视频| ssswww日本免费网站片| 久久国产亚洲观看| 2022免费国产精品福利在线| 久久影院亚洲一区| 99在线视频免费| 亚洲伊人久久大香线蕉在观| 久艹视频在线免费观看| 亚洲成人动漫在线观看| 在线播放高清国语自产拍免费| 思思久久99热免费精品6| 亚洲国产二区三区久久| 两个人看的www高清免费观看| 久久亚洲AV成人无码电影| 国产精品免费看久久久| 亚洲一卡二卡三卡| 亚洲AV伊人久久青青草原| 久久亚洲中文无码咪咪爱| 在线A亚洲老鸭窝天堂| 亚洲视频免费播放| 美女被免费视频网站| 亚洲AV乱码久久精品蜜桃| 拔擦拔擦8x华人免费久久 | 亚洲精品无码久久久久牙蜜区|