Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过ASP NET核心中的HTTP请求记录IIS自定义字段_C#_Asp.net Core_Httprequest_Middleware_Iis Logs - Fatal编程技术网

C# 通过ASP NET核心中的HTTP请求记录IIS自定义字段

C# 通过ASP NET核心中的HTTP请求记录IIS自定义字段,c#,asp.net-core,httprequest,middleware,iis-logs,C#,Asp.net Core,Httprequest,Middleware,Iis Logs,我已经为我的网站启用了带有自定义字段的IIS日志记录 在之前的MVC中,我使用HTTPHandlers和Module将上述字段添加到HTTP请求头中 web.config: <modules runAllManagedModulesForAllRequests="true"> <!--Handler to process the IIS logs of the site Pagevisit logs--> <add name="IISLogge

我已经为我的网站启用了带有自定义字段的IIS日志记录

在之前的MVC中,我使用HTTPHandlers和Module将上述字段添加到HTTP请求头中

web.config:

 <modules runAllManagedModulesForAllRequests="true">
     <!--Handler to process the IIS logs of the site Pagevisit logs-->
    <add name="IISLogger" type="MySite.Website.MvcApplication.Utils.IISLogHandler, MySite.Website.MvcApplication" />
</modules>
public class IISLogHandler : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
        }

        private void context_BeginRequest(object sender, EventArgs e)
        {
              var request = (sender as HttpApplication).Request;
              request.Headers["IIID"] = iiid;
              request.Headers["IID"] = !string.IsNullOrEmpty(customerId) ? 
               customerId : iid;

        }
}
我生成的日志:

 <modules runAllManagedModulesForAllRequests="true">
     <!--Handler to process the IIS logs of the site Pagevisit logs-->
    <add name="IISLogger" type="MySite.Website.MvcApplication.Utils.IISLogHandler, MySite.Website.MvcApplication" />
</modules>
public class IISLogHandler : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
        }

        private void context_BeginRequest(object sender, EventArgs e)
        {
              var request = (sender as HttpApplication).Request;
              request.Headers["IIID"] = iiid;
              request.Headers["IID"] = !string.IsNullOrEmpty(customerId) ? 
               customerId : iid;

        }
}


如何将其迁移到ASPNET Core 2.2.0

也许您可以在中间件中使用HttpContext来实现类似的功能。