【问题标题】:Application_BeginRequest not firing (NOT URL rewrite)Application_BeginRequest 未触发(不是 URL 重写)
【发布时间】:2013-12-13 20:54:04
【问题描述】:

我想写出 SOAP Web 服务的传入请求。原来我的 Application_BeginRequest 事件没有触发。它在 IIS6 和 Windows 2003 上运行,因此其他地方推荐的配置更改没有任何效果。

protected void Application_BeginRequest(object sender, EventArgs e) { 尝试 { byte[] inputBytes = new byte[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”。

感谢您的建议。

【问题讨论】:

    标签: asp.net web-services httprequest global-asax


    【解决方案1】:

    此问题最可能的原因是该站点未设置为应用程序。

    【讨论】:

    • 我记得曾几何时,“网站”和“Web 应用程序”之间存在区别,但我认为这不再存在。我相信它是一个 Web 应用程序,但我会研究一下,因为它不是我在 IDE 或 Web 服务器上研究过的东西。
    猜你喜欢
    • 1970-01-01
    • 2015-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-03
    • 1970-01-01
    • 2013-07-20
    相关资源
    最近更新 更多