❔ 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, ...
S
Senpawaii•398d ago
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.
A
Accord•397d ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
51KMembers
View on DiscordWant results from more Discord servers?
More Posts❔ XMLAttributeCollection -> Dictionary with LINQ?It's a confusing class. It only allows turning it into a Queryable, but I have no experience with th❔ MS SQL Reporting Server URL Being RedirectedWe have an application from a vendor that was written in C# and we recently upgraded the MS SQL data❔ dataset memory leakI found memory leak and I don't understand how to fix it
Test case:
```cpp
public class MemoryLeaksT❔ WebAPI .NET 7.0 - Encrypt connectionstring in appsettings.jsonguys, I'm writing some WebAPI using .NET 7.0, and I'd like to secure the connectionstring with encry❔ how to read strings correctly with System.Data.SQLitei m trying read turkish characters from database but i can't see correctly❔ Blazor server app, base url / base page to set environmentHi 🙂
I have a Blazor Server app, where I would like to use some dynamic baseurl.
Say instead of my❔ C# Console Application -its only writing the same random string, how can i make it do different ones?❔ Rapid prototypingDo you feel there is such a thing as rapid prototyping or mvp development where you do things differ❔ HotChocolate with IQueryable, apply a required filter on the ef entityBasically, I'm trying to find a way to configure an `IObjectFieldDescriptor` by adding a required ar❔ Dev/prod databseHello,
Me and a friend wants to create a webb-app project with a react frontend and C# backend.