Losing session user id between layers

Hi,
When the request is coming in, I am getting UserAuthId in the Service with a proper value:

image

Inside InserFilter, the value is gone.

I am using services.AddHttpContextAccessor(); to enable HTTP context.

What can go wrong? why is the session lost on the way from service stack service to InserFilter…

Thanks

You’re not looking at the same session instance when you’re accessing the Request Instance via a singleton, it has to re-create it (i.e. reload it from the registered ICacheClient) using the ss-id/ss-pid Session Cookies sent with the request.

What’s the full output of GetSession()? Does it return the same Authenticated Session? Are the ss-id/ss-pid Cookies the same?

Please explain this, I have never used it. Took it from your example: c# - How to get current user from ServiceStack.Logging - Stack Overflow

I assume I’m misusing it.

This is the full GetSession inside insert filter:

this is inside the service:

Thanks

The first screenshot is of an Un Authenticated user so it’s not able to re-create the Session.

Can you provide the Request Cookies for both to see if they match? Also what version of ServiceStack are you using?

No cookies are invalved, it is JWT using IHasBearerToken .and [Autenticate]
Im using 5.8.0

BTW, this is the actual problem. in the service the session is fine. in the filter the id is null.
The entire stack is awaited.

Does the Request still have the Bearer Token in the HTTP Authentication header populated?

Can you try upgrading to v5.8.1 on MyGet.

Yes returning an UnAuthenticated session is definitely the issue, and it’s fine in the Service because of what I’ve described, accessing the Request Context through a singleton context doesn’t look at the same instance, it has to try re-create it again from the Request Cookies/Headers.

Seems to be working now…
just to make sure its not accedental. is 5.8.1 really handle that issue?
Thanks for you kind help

Yep, it’s now attaching ServiceStack’s Request Context to .NET Core’s Request Object so it should now be referencing the same IRequest instance.

Thanks! appreceated…

When I build my dockers, I am gettign these errors because of the upgrade:

/src/EyezServices.Lib/EyezServices.Lib.csproj : error NU1102: Unable to find package ServiceStack.Api.OpenApi.Core with version (>= 5.8.1) [/src/EyezServices.Client/EyezServices.Client.csproj]
/src/EyezServices.Lib/EyezServices.Lib.csproj : error NU1102:   - Found 13 version(s) in nuget.org [ Nearest version: 5.8.0 ] [/src/EyezServices.Client/EyezServices.Client.csproj]
/src/EyezServices.Lib/EyezServices.Lib.csproj : error NU1102: Unable to find package ServiceStack.Logging.Serilog with version (>= 5.8.1) [/src/EyezServices.Client/EyezServices.Client.csproj]
/src/EyezServices.Lib/EyezServices.Lib.csproj : error NU1102:   - Found 14 version(s) in nuget.org [ Nearest version: 5.8.0 ] [/src/EyezServices.Client/EyezServices.Client.csproj]
/src/EyezServices.Lib/EyezServices.Lib.csproj : error NU1102: Unable to find package ServiceStack with version (>= 5.8.1) [/src/EyezServices.Client/EyezServices.Client.csproj]
/src/EyezServices.Lib/EyezServices.Lib.csproj : error NU1102:   - Found 185 version(s) in nuget.org [ Nearest version: 5.8.0 ] [/src/EyezServices.Client/EyezServices.Client.csproj]
/src/EyezServices.Lib/EyezServices.Lib.csproj : error NU1102: Unable to find package ServiceStack.OrmLite with version (>= 5.8.1) [/src/EyezServices.Client/EyezServices.Client.csproj]
/src/EyezServices.Lib/EyezServices.Lib.csproj : error NU1102:   - Found 60 version(s) in nuget.org [ Nearest version: 5.8.0 ] [/src/EyezServices.Client/EyezServices.Client.csproj]
/```

Include a NuGet.Config next to your solution so that the restore task will source its packages from MyGet instead.

Odd. I already did that… Should I point to it from somewhere?

It should be using the local NuGet.Config by default but you can specify it in the restore command with the --configfile <FILE> option which should tell you if it can’t find it.