Application_BeginRequest未触发(不是URL重写)
问题描述:
我想写出传入的SOAP Web服务请求。原来,我的Application_BeginRequest事件没有触发。它运行在Windows 2003的IIS6 &上,因此其他地方推荐的配置更改没有任何影响。Application_BeginRequest未触发(不是URL重写)
保护无效的Application_BeginRequest(对象发件人,EventArgs的) { 尝试 { 字节[] inputBytes =新的字节[HttpContext.Current.Request.ContentLength];
HttpContext.Current.Request.InputStream.Position = 0;
HttpContext.Current.Request.InputStream.Read(inputBytes, 0, inputBytes.Length);
string requestString = ASCIIEncoding.ASCII.GetString(inputBytes);
Logger.Write("input: " + Convert.ToString(inputBytes.Length), Global.LOGGER_EVENT_SOURCE, 0, 0, TraceEventType.Warning);
using (var writer = new StreamWriter(@"c:\inetpub\wwwroot\requests\testfile - " + DateTime.Now.ToString("MMddYYYYhhmmssffff") + ".xml"))
{
writer.Write(requestString);
writer.Close();
}
// Reset stream pointer to beginning.
HttpContext.Current.Request.InputStream.Position = 0;
}
catch (Exception ex)
{
// Error handling; omitted here.
}
}
代码“几乎”作品,如果我只是把它被调用的Web服务方法的内部;文件被创建,但请求的内容长度为'0'。
感谢您的任何建议。
答
此问题最可能的原因是该网站未设置为应用程序。
我记得曾经有一个'网站'和'网络应用程序'之间的区别,但我不认为这已经存在了。我相信它是一个Web应用程序,但我会研究这一点,因为它不是我在IDE或Web服务器上查看的内容。 –