Asp.net core 如何使用类绑定/注册当前http请求的用户
通过使用WebAPI2的Autofac,我可以将当前http请求实例绑定到某个c#类 如果没有autofac,我如何使用asp.net core做到这一点Asp.net core 如何使用类绑定/注册当前http请求的用户,asp.net-core,autofac,asp.net-core-1.1,Asp.net Core,Autofac,Asp.net Core 1.1,通过使用WebAPI2的Autofac,我可以将当前http请求实例绑定到某个c#类 如果没有autofac,我如何使用asp.net core做到这一点 IServiceCollection services 您可以注册IHttpContextAccessor并将其注入到您的服务中 services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton(); 然后您可以
IServiceCollection services
您可以注册
IHttpContextAccessor
并将其注入到您的服务中
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSingleton();
然后您可以通过httpContextAccessor.HttpContext
访问HttpContext。谢谢,现在也找到了:p