IIS 托管模块 AddOnBeginRequestAsync 不需要结果

问题描述 投票:0回答:0

试图将搜索日志保存到本地文件中。我需要它的异步处理程序,但 AddOnBeginRequestAsync 需要从 BeginRequest、EndRequest 返回的 IAsyncResult。没有它怎么办?返回 null - 不工作。

P。 S. 这是 IIS 托管模块。

public void Dispose()
{
}

public bool IsReusable
{ get { return false; } }

public void Init(HttpApplication app)
{
    app.AddOnBeginRequestAsync(BeginRequest, EndRequest);
}
        
private IAsyncResult BeginRequest(object sender, EventArgs e, AsyncCallback cb, object extraData)
{
    string reqPath = HttpContext.Current.Request.Url.PathAndQuery;
    bool correctString = reqPath.Contains("/?search=");

    if (HttpContext.Current.Request.HttpMethod == "POST" && correctString)
    {
        using (var reader = new StreamReader(HttpContext.Current.Request.InputStream))
        {
            string searchData = HttpUtility.UrlDecode(reader.ReadToEnd());
        }
        File.AppendAllText(workDir + "search_log.txt", searchData);
    }
}

private void EndRequest(IAsyncResult ar)
{
    return;
}

当return null添加到BeginRequest时,会出现“System.NullReferenceException”错误。

c# asynchronous iis module managed
© www.soinside.com 2019 - 2024. All rights reserved.