Open Closed

微服务语言包资源未加载及网页会自动刷新回首页问题 #10180


User avatar
0
2250368121 created
  • Steps to reproduce the issue:
  • 请问 我添加的微服务经常会出现语言包未加载的问题如图所示 我有一个BaseSetService的服务 在语言文本的资源中找不到,过段时间又会加载出来,我想知道语言资源包加载是通过那个服务加载的,另外我们还发现系统会在每过45分钟左右网页自动刷新一次而回到网页的首页上,无论是否在操作中还是无动作的情况下

3 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    1. Solution
    • How ABP loads localization in a microservice solution
      • In the microservice template, the Administration (or LanguageService if dynamic localization is enabled) microservice aggregates localization. All UI/apps get texts from the Application Localization endpoint via the gateway:
        • GET /api/abp/application-localization?cultureName=xx
      • Each microservice defines its own resources (e.g., BaseSetServiceResource) in its contracts/domain and registers them on startup. The Language Management infrastructure persists/serves these resources to the Administration service, which then responds to the endpoint above.
      • If a resource intermittently “disappears” from the Language Texts page or from the dropdown, check:
        1. The microservice hosting that resource is running and has started successfully.
        2. The resource assembly is referenced by the microservice host and the resource is added in the module class, for example:
    [DependsOn(/* ... */)]
          public class QRSPCBaseSetServiceDomainSharedModule : AbpModule
          {
              public override void ConfigureServices(ServiceConfigurationContext context)
              {
                  Configure<AbpLocalizationOptions>(options =>
                  {
                      options.Resources
                          .Add<BaseSetServiceResource>("en")
                          .AddBaseTypes(typeof(AbpValidationResource))
                          .AddVirtualJson("/Localization/BaseSetService"); // folder with zh-Hans.json etc.
                  });
              }
          }
    
    3) The gateway routes /api/abp/application-localization to Administration and no cache inconsistency exists (see next).
    4) If dynamic localization is enabled, ensure the Language Management DB contains the resource (initial registration occurs on first start of the resource-owning service). Restarting the service re-registers resources if needed.
    
    • Caching considerations for intermittent missing resources

      • The application-localization response is cached by clients while the backend reads from the Language Management store. In clustered deployments, use a distributed cache (e.g., Redis) for consistent results across instances. If you see intermittent visibility:
        • Ensure all services (including Administration) share the same distributed cache and database.
        • After deploying a new service or changing localization files, recycle the Administration service and clear distributed cache to avoid stale entries.
        • Verify the gateway and Administration instances are healthy; a failing instance behind load-balancer may respond without the new resource.
    • Why the page returns to Home every ~45 minutes

      • This is almost always due to authentication/session validation rather than localization. Two common causes:
        1. Security stamp validation/sign-in cookie validation cycle (for MVC/Angular with OpenIddict/Identity). If the cookie expires or security-stamp validation fails, the UI is redirected to re-authenticate, which brings the app back to its root.
        2. Access token expiry/refresh failure in SPA: if the token expires and refresh does not happen (or fails), the app reloads and lands on the root.
      • What to check:
        • Token lifetimes and cookie expiration/SlidingExpiration in your Auth Server configuration. Make sure the Angular/MVC client refreshes tokens correctly and that the allowed clock skew and refresh token settings are configured.
        • If running behind a gateway, ensure the issuer configuration (AuthServer:Authority) is correct for all services so validation doesn’t fail when tokens rotate.
        • Confirm data protection keys are persisted and shared across instances, otherwise cookies become invalid after key rotation and users get logged out periodically.
    • Diagnostics checklist

      1. Call, via the gateway, while the problem occurs:
        • GET /api/abp/application-localization?cultureName=zh-Hans&onlyDynamics=false
        • Confirm “resources” includes your BaseSetService resource name.
      2. Inspect the Administration service logs when the resource is missing; you should see the resource registration on the service startup. If not, verify the module configuration and that the assembly with localization files is loaded by the host.
      3. Ensure your JSON files are embedded/virtual (Virtual File System) and the path in AddVirtualJson matches the folder name.
      4. Verify distributed cache and DB connection strings are the same across all instances.
      5. For the 45-minute refresh:
        • Check token/cookie lifetimes in the Auth Server and whether the SPA is performing silent refresh. If necessary, increase lifetimes to confirm the behavior changes, then tune properly.
    1. Sources
    • https://abp.io/docs/latest/framework/architecture/modularity/basics
    • https://abp.io/docs/latest/framework/api-development/standard-apis/localization
    • https://abp.io/docs/latest/framework/fundamentals/localization
    • https://abp.io/docs/latest/solution-templates/microservice/localization-system

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    你好

    请分享下你的整个解决方案的项目结构

    谢谢

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    你可以检查下数据库的LocalizationResources表.

    另外BaseSetService是否直接或者间接依赖了LanguageManagementDomainModule?

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.1.0-preview. Updated on December 05, 2025, 12:34
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.