■87870 |
Re[2]: ASPもしくはIISでhttpレスポンスボディを確認する方法 |
□投稿者/ abc -(2018/07/09(Mon) 13:45:53)
| ■No87869 (WebSurfer さん) に返信
ご確認までして頂きありがとうございます。
現状報告としまして、レスポンスボデイが取得できることは確認できましたが実装で引っ掛かっている状態です。
・ウェブページは正常に表示されるが、ログ上ではobject movedとなってしまい、以降記録されない
・今の方法だとアプリケーションプールが統合モードでしか動かないが、クラシックモードで実現したい(できれば)
■ログ
[Request]2018/07/09 13:26:10:
http://localhost:8888/hoge.aspx
[Response]2018/07/09 13:26:13:
(意図する正常なhtml)
[Request]2018/07/09 13:26:17:
http://localhost:8888/hoge.aspx
[Response]2018/07/09 13:26:17:
<h tml><h ead><t itle>Object moved</t itle></h ead><b ody>
<h 2>Object moved to <a h ref="hoge.aspx">here</ a>.</h 2>
</b ody></html>
[Request]2018/07/09 13:26:17:
http://localhost:8888/hoge.aspx
[Response]2018/07/09 13:26:17:
(以降記録されず……)
■ソース
※OutputFilterStreamはご紹介頂いた下記URLのものをコピペしています。
https://stackoverflow.com/questions/1038466/logging-raw-http-request-response-in-asp-net-mvc-iis7#
public class Logger : IHttpModule
{
static readonly string responseLogPath = @"D:\test.txt";
OutputFilterStream filter;
public void Init(HttpApplication application)
{
application.BeginRequest += (new EventHandler(this.Application_BeginRequest));
application.EndRequest += (new EventHandler(this.Application_EndRequest));
}
public void Dispose()
{
}
private void Application_BeginRequest(Object sender, EventArgs e)
{
HttpResponse response = HttpContext.Current.Response;
WriteLog("[Request]" + DateTime.Now + ":" + Environment.NewLine + HttpContext.Current.Request.Url.ToString());
filter = new OutputFilterStream(response.Filter);
response.Filter = filter;
}
private void Application_EndRequest(object sender, EventArgs e)
{
WriteLog("[Response]" + DateTime.Now + ":" + Environment.NewLine + filter.ReadStream());
}
private void WriteLog(string log)
{
using (var sw = new StreamWriter(responseLogPath, true))
{
sw.WriteLine(log);
}
}
}
|
|