Open Closed

I want to ask about the RootUrl. In a SaaS situation, where each of our users has a different domain, how can we dynamically set the RootUrl? #10012


User avatar
0
rexhxiao created

In this case, you would typically need to capture the user's domain dynamically at runtime and set the RootUrl accordingly. Depending on how your application is structured, you might consider using the Request object to determine the domain of the current request and configure the RootUrl based on that.

For example:

.Configure<PaymentWebOptions>(options =>
{
    var currentDomain = HttpContext.Request.Host.Value; // Get the current domain dynamically
    options.RootUrl = $"https://{currentDomain}";
    options.CallbackUrl = $"https://{currentDomain}/Payment/Success";
    options.GatewaySelectionCheckoutButtonStyle = configuration["Payment:GatewaySelectionCheckoutButtonStyle"];
});

This approach grabs the domain from the current HTTP request, allowing each user to have their own dynamically configured RootUrl.


5 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent

    To dynamically set the RootUrl in a SaaS (multi-tenant, multi-domain) scenario with ABP Framework, you should use the domain/subdomain tenant resolver and configure your application to use placeholders in your configuration files. This allows the application to resolve the tenant and domain at runtime, ensuring the correct RootUrl is used for each tenant.

    Step-by-step Solution

    1. Use Placeholders in Configuration In your appsettings.json or relevant configuration, use the {0} placeholder for tenant-specific domains:
    "App": {
         "SelfUrl": "https://{0}.yourdomain.com",
         "SelfUrlWithoutTenant": "https://yourdomain.com"
       }
    
    1. Configure Tenant Resolver in Startup In your module's ConfigureServices method, add the domain tenant resolver:
    Configure<AbpTenantResolveOptions>(options =>
       {
           options.AddDomainTenantResolver(configuration["App:SelfUrl"]);
       });
    
    1. Dynamically Set RootUrl at Runtime When you need to set the RootUrl (e.g., for payment callbacks), use the current request's host to build the URL:
    services.Configure<PaymentWebOptions>(options =>
       {
           var httpContextAccessor = services.BuildServiceProvider().GetRequiredService<IHttpContextAccessor>();
           var currentDomain = httpContextAccessor.HttpContext?.Request.Host.Value;
           options.RootUrl = $"https://{currentDomain}";
           options.CallbackUrl = $"https://{currentDomain}/Payment/Success";
       });
    

    Make sure to register IHttpContextAccessor in your DI container:

    services.AddHttpContextAccessor();
    
    1. Frontend (if applicable) For Angular or Blazor, use the {0} placeholder in your environment or appsettings files, and replace it at runtime based on the current domain.

    Notes

    • This approach ensures each tenant's domain is used for RootUrl and callback URLs.
    • The {0} placeholder is replaced by the tenant name/domain at runtime by ABP's multi-tenancy infrastructure.

    Sources


    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

    hi

    What is your payment provider?

    PayPal or TwoCheckout?

    Thanks.

  • User Avatar
    0
    rexhxiao created

    We are currently using PAYUNi as our payment provider (https://www.payuni.com.tw/). Will using different payment providers have any impact?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    If your abp version >= 7.4.2, Payment module will support getting the current tenant URL

    See https://abp.io/support/questions/6003/Stripe-payment-module-tenantName-resolver-issue

    Thanks.

  • User Avatar
    0
    rexhxiao created

    We didn’t see the part where “Payment module will support getting the current tenant URL.” Our tenant domains can vary, for example: https://{0}.mydomain.com https://snapshop-a.mydomain.com or https://www.snapshop-b.com

    All of the above belong to the same SaaS application system. We need to dynamically generate the corresponding domain URLs. Could you please show us how to achieve this?

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 October 17, 2025, 13:15