簡體   English   中英

通過HttpModule確定頁面大小

[英]Determine size of page via HttpModule

這對你來說很簡單:

我目前正在通過HttpModule記錄請求持續時間,我想知道每個頁面的字節數。

HttpContext.Current.Response.OutputStream.Length拋出NotSupportedException

有什么簡單的方法可以做到這一點?

我有一個實現流重寫器的HttpModule。 它派生自Stream類。 在我的HttpModule中,我有以下代碼:

void app_PreRequestHandlerExecute(object sender, EventArgs e)
{
    HttpResponse response = HttpContext.Current.Response;
    response.Filter = new MyRewriterStream(response.Filter);
}

在stream類中,我有以下代碼覆蓋默認的Write方法:

public override void Write(byte[] buffer, int offset, int count)
{
     string outStr;
     outStr = UTF8Encoding.UTF8.GetString(buffer, offset, count);
     //Do useful stuff and write back to the stream
}

您可以在第二點獲取字符串的長度

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM