0

次のようにIHttpModuleから派生させた後、HTTPModule を作成しました。

public void Init(HttpApplication httpApplication)
{
    EventHandlerTaskAsyncHelper taskAsyncHelper = new EventHandlerTaskAsyncHelper(LogMessage);
    httpApplication.AddOnBeginRequestAsync(taskAsyncHelper.BeginEventHandler, taskAsyncHelper.EndEventHandler);
}

private async Task LogMessage(object sender, EventArgs e)
{
           var app = (HttpApplication)sender;
            var ctx = app.Context;
           string myURL = ((HttpApplication)sender).Context.Request.Url.ToString();

          StreamReader reader = new StreamReader(((HttpApplication)sender).Context.Request.InputStream);

            try
            {
                string body = reader.ReadToEnd();
            }
            finally
            {
                reader.BaseStream.Position = 0;
            }

            StreamReader ResponseStreamReader = new StreamReader(((HttpApplication)sender).Context.Response.OutputStream);

}

StreamReader コードがエラーをスローしています (正確なエラー メッセージは次のとおりです: System.ArgumentException: ストリームが読み取れませんでした)。

HTTP リクエストの ResponseBody を読み取るにはどうすればよいですか。私は.Net 4.5を使用しています。ありがとう、ジョン

4

2 に答える 2