❔ Accessing HTTP Context at DbCommandInterceptor [.NET 7]
Hi! I'm having some issues trying to access the HTTP Context at my DbCommand Interceptor class.
What I'm trying to achieve is similar to the one presented in: https://stackoverflow.com/questions/75033870/getting-httpcontext-or-just-user-information-into-dbconnectioninterceptor-in
I have tried following advices as present in https://weblogs.asp.net/ricardoperes/accessing-the-httpcontext-from-a-dbcontext , however, when I try to access the HttpContext from the IHttpContextAccessor, I always get a Null object.
Ultimately, what I want to do is inject the IHttpContextAccessor class through the DbContext class’ constructor, so that I can provide it to the Interceptor.
Can someone lend me some much appreciated advice on how to solve this?
This is the implementation of my Interceptor.
Stack Overflow
Getting HttpContext (or just user information) into DbConnectionInt...
I am trying to setup RLS by running sp_set_session_context at the point of connection to my SQL Server database via a DbConnectionInterceptor. It works fabulously when I use a hardcoded Username, ...
2 Replies
The implementation of the custom DbContext class, where the Interceptor is added:
How I configure my Services and dependencies (using Autofac):
And finally the implementation of AddCustomDbContext, called on the previous code block.
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.