Blazor Server App

My App is a blazor server app, buiid with the servicestack template.
I want to get the user data in a service.

I can’t find the reason why this doesn’t works:

With getSession() I can’t get any data like login user, etc.

[Authenticate]
public class ObjektListServices : Service
{
    public object Get(GetObject4Gridview request)
    {
        var userId = this.GetSession().UserAuthId;
        ...
    }
}

The value for userid is null, although I have a login user.

Alois

When reporting issues please provide enough context to be able to identify and reproduce the issue.

What template did you use? Are you using the default Auth configuration? If not please post a repro to a GitHub repro and I’ll take a look.

I use the default blazor server template with the default Auth configuration

Do you mean https://github.com/NetCoreTemplates/blazor?

If not specify which command you used to create it or screenshot of icon you clicked on do download it

image

Now within the MyService Class:

public class MyServices : Service
{
    public object Any(Hello request)
    {
        var userId = this.GetSession().UserAuthId;
        return new HelloResponse { Result = $"Hello, {request.Name}!" };
    }
}

Thanks, can you confirm you’ve also added [ValidateIsAuthenticated] to the Hello Request DTO?


FYI you need to put C# code inside csharp code fences to properly format it, e.g:

```csharp
// C# code...
```

Stange think, I started from scratch we a new template, same did for 4 weeks.

This did it.

So wait, I compare what’s different.

I found the reason, at the end.
The reason is, cause I made service call :

var api = await ApiAsync(new Object4gridview());

Add of course then you find any session data.

Is there a recommended way for that?

I would like to have session data within the service, to know what is the actual user.

Alois

I don’t know what this question is asking, please post a stand-alone repro on GitHub that I can run locally to reproduce the issue.