Open Closed

CurrentUser.Roles is empty #2628


User avatar
0
zhongfang created
  • ABP Framework version: v5.1.3
  • UI type: Blazor Server Side
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace: Nothing
  • Steps to reproduce the issue:"
  • I created tired application with ABP Suite 5.1.3
  • In razor pages of Blazor project, @CurrentUser.Roles.JoinAsString(", ") get null output
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

14 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    Can you share some codes?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    zhongfang created

    <strong>@L["Roles"]</strong>: @CurrentUser.Roles.JoinAsString(", ")

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    Sorry, the code you provided is too simple, I can't reproduce the problem. Could you provide the full steps? thank you.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    zhongfang created

    A TIRED blazor server side application。 I think it is caused by some configuration such as CORS to call API?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    A TIRED blazor server side application。

    Please share the code of the ConfigureAuthentication method.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    zhongfang created

    private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration) { context.Services.AddAuthentication(options => { options.DefaultScheme = "Cookies"; options.DefaultChallengeScheme = "oidc"; }) .AddCookie("Cookies", options => { options.ExpireTimeSpan = TimeSpan.FromDays(365); }) .AddAbpOpenIdConnect("oidc", options => { options.Authority = configuration["AuthServer:Authority"]; options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]);; options.ResponseType = OpenIdConnectResponseType.CodeIdToken; options.ClientId = configuration["AuthServer:ClientId"]; options.ClientSecret = configuration["AuthServer:ClientSecret"]; options.SaveTokens = true; options.GetClaimsFromUserInfoEndpoint = true; options.Scope.Add("role"); options.Scope.Add("email"); options.Scope.Add("phone"); options.Scope.Add("Brain"); }); }

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    I cannot reproduce the problem, please create a new project and try again.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    zhongfang created

    There is an warning message whilt starting the web host.

    [02:56:00 INF] Initialized all ABP modules.
    [02:56:00 INF] Initializing UI Database
    [02:56:00 INF] Now listening on: http://[::]:80
    [02:56:00 INF] Application started. Press Ctrl+C to shut down.
    [02:56:00 INF] Hosting environment: ba****o_com
    [02:56:00 INF] Content root path: /app/
    [02:56:06 INF] Request starting HTTP/1.0 GET http://abc.ba****o.com/health - -
    [02:56:06 WRN] Could not find IdentityClientConfiguration for AbpMvcClient. Either define a configuration for AbpMvcClient or set a default configuration.
    [02:56:06 INF] Start processing HTTP request GET https://frontapi.bazishuo.com/api/abp/application-configuration?api-version=1.0
    [02:56:06 INF] Sending HTTP request GET https://frontapi.ba****o.com/api/abp/application-configuration?api-version=1.0
    [02:56:07 INF] Received HTTP response headers after 728.2914ms - 200
    [02:56:07 INF] End processing HTTP request after 742.2128ms - 200
    [02:56:08 WRN] Could not find IdentityClientConfiguration for AbpMvcClient. Either define a configuration for AbpMvcClient or set a default configuration.
    [02:56:08 INF] Start processing HTTP request GET https://frontapi.ba****o.com/api/abp/application-configuration?api-version=1.0
    [02:56:08 INF] Sending HTTP request GET https://frontapi.ba****o.com/api/abp/application-configuration?api-version=1.0
    [02:56:09 INF] Request starting HTTP/1.0 POST http://app.ba****o.com/_blazor/negotiate?negotiateVersion=1 text/plain;charset=UTF-8 0
    [02:56:09 INF] Received HTTP response headers after 787.906ms - 200
    

    appsettings.ba****o_com

      "RemoteServices": {
        "Default": {
          "BaseUrl": "https://frontapi.ba****o.com/"
        },
        "Brain": {
          "BaseUrl": "https://api.another.tech/"
        },
        "AbpAccountPublic": {
          "BaseUrl": "https://id.ba****o.com/"
        }
      },
      "AuthServer": {
        "Authority": "https://id.ba****o.com",
        "RequireHttpsMetadata": "false",
        "ClientId": "****",
        "ClientSecret": "****"
      },
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    zhongfang created

    [02:56:06 WRN] Could not find IdentityClientConfiguration for AbpMvcClient. Either define a configuration for AbpMvcClient or set a default configuration.

    as you see, I have default remote service.

    What does the warn mean?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    You need this configuration.

    {
      "IdentityClients": {
        "Default": {
          "GrantType": "password",
          "ClientId": "MyProjectName_App",
          "ClientSecret": "1q2w3e*",
          "UserName": "admin",
          "UserPassword": "1q2w3E*",
          "Authority": "https://localhost:44301",
          "Scope": "MyProjectName"
        }
      }
    }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    zhongfang created

    I never heard such configuration. I need to store a valid username with password in config file?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Can you try with a new template project?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    zhongfang created

    Which template project will use below config? Or any document about below configuration?

    {
      "IdentityClients": {
        "Default": {
          "GrantType": "password",
          "ClientId": "MyProjectName_App",
          "ClientSecret": "1q2w3e*",
          "UserName": "admin",
          "UserPassword": "1q2w3E*",
          "Authority": "https://localhost:44301",
          "Scope": "MyProjectName"
        }
      }
    }
    
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    https://github.com/abpframework/abp/blob/dev/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/appsettings.json#L7

    HttpApi.Client.ConsoleTestApp is not an automated test application. It is an example Console Application that shows how to consume your HTTP APIs from a .NET Console Application.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.