Skip to content

Commit b71ca70

Browse files
authored
Merge pull request #337 from aspnetzero/add-subdomain-based-multi-tenancy-doc
Add reference subdomain-based multi-tenant in overview document
2 parents de58900 + 049fab7 commit b71ca70

File tree

4 files changed

+37
-33
lines changed

4 files changed

+37
-33
lines changed

docs/en/Overview-Angular.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ There may be other ways of doing it but this is the simplest way.
109109

110110
> In the development time, you don't need to use subdomains for tenants for a simpler development experience. When you do like that, a 'tenant switch' dialog is used to manually switch between tenants.
111111

112+
> For advanced scenarios and production-level configuration of subdomain-based multi-tenancy in ASP.NET Zero Angular applications, including SSL setup, IIS configuration, local development strategies, and tenant resolution internals, please refer to the extended documentation here: [Subdomain-Based Multi-Tenancy in ASP.NET Zero (Angular)](Subdomain-Based-Multi-Tenancy-Angular.md)
113+
112114
Check out the [multi tenant documentation](https://aspnetboilerplate.com/Pages/Documents/Multi-Tenancy) if you are building multi-tenant applications.
113115
114116
### Angular Solution

docs/en/Overview-Core.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ There may be other ways of doing it but this is the simplest way.
8787

8888
> In the development time, you don't need to use subdomains for tenants for a simpler development experience. When you do like that, a 'tenant switch' dialog is used to manually switch between tenants.
8989

90+
> For advanced scenarios and production-level configuration of subdomain-based multi-tenancy in ASP.NET Zero MVC applications, including SSL setup, IIS configuration, local development strategies, and tenant resolution internals, please refer to the extended documentation here: [Subdomain-Based Multi-Tenancy in ASP.NET Zero (MVC)](Subdomain-Based-Multi-Tenancy-MVC.md)
91+
9092
Check out the [multi tenant documentation](https://aspnetboilerplate.com/Pages/Documents/Multi-Tenancy) if you are building multi-tenant applications.
9193
9294
Similar to **WebSiteRootAddress**, **ServerRootAddress** setting is also exists in `appsettings.json` in .Web.Host project.

docs/en/Subdomain-Based-Multi-Tenancy-Angular.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Subdomain-Based Multi-Tenancy in ASP.NET Zero (Angular)
1+
# Subdomain Based Multi Tenancy in ASP.NET Zero (Angular)
22

33
## Introduction
44

5-
This document provides detailed guidance for configuring and troubleshooting subdomain based multi-tenancy in ASP.NET Zero projects utilizing an Angular frontend. It expands upon the foundational knowledge offered in the official documentation, aiming to cover advanced configurations, development environment strategies, and common issues.
5+
This document provides detailed guidance for configuring and troubleshooting subdomain based multi tenancy in ASP.NET Zero projects utilizing an Angular frontend. It expands upon the foundational knowledge offered in the official documentation, aiming to cover advanced configurations, development environment strategies, and common issues.
66

77
This document assumes you have a basic understanding of ASP.NET Zero's multi tenancy concepts and have reviewed the main [Overview Angular](Overview-Angular.md) documentation.
88

9-
## 1. Configuration for Subdomain-Based Tenancy
9+
## 1. Configuration for Subdomain Based Tenancy
1010

1111
This section involves SSL management, web server setup, and specific Angular application settings.
1212

@@ -26,7 +26,7 @@ This section involves SSL management, web server setup, and specific Angular app
2626
* For HTTP binding (port 80), you can often leave the "Host Name" field empty if it's the only site on that IP, or specify each primary domain if needed.
2727
* For HTTPS binding (port 443), select the appropriate wildcard SSL certificate. The host name field might be left blank or set if your IIS version supports specific SNI configurations with wildcards, but often the wildcard nature is primarily handled by the certificate itself. The key is that IIS listens for traffic on the IP and port, and the certificate validates for `*.mydomain.com`.
2828
* **Default Document/Application:** Ensure your IIS site is configured to correctly serve the Angular application (typically `index.html` and other static assets from your `dist` folder) for all subdomain requests that point to the client application.
29-
* **URL Rewrite (If Necessary):** While ASP.NET Zero's framework handles tenant resolution based on the host, complex infrastructures involving reverse proxies might require URL Rewrite rules. However, for standard deployments, this is generally not needed for the core multi-tenancy functionality.
29+
* **URL Rewrite (If Necessary):** While ASP.NET Zero's framework handles tenant resolution based on the host, complex infrastructures involving reverse proxies might require URL Rewrite rules. However, for standard deployments, this is generally not needed for the core multi tenancy functionality.
3030

3131
### Angular Application (`appsettings.json`) Specifics
3232

@@ -43,13 +43,13 @@ This section involves SSL management, web server setup, and specific Angular app
4343
}
4444
```
4545
* **Tenant Resolution in Angular:**
46-
* ASP.NET Zero's client-side infrastructure typically uses the `ServerRootAddress`. The framework includes logic to dynamically replace the `{TENANCY_NAME}` placeholder based on the current browser URL's subdomain.
46+
* ASP.NET Zero's client side infrastructure typically uses the `ServerRootAddress`. The framework includes logic to dynamically replace the `{TENANCY_NAME}` placeholder based on the current browser URL's subdomain.
4747
* This ensures that API calls generated by `NSwag` or other service proxies are directed to the correct tenant specific backend endpoints.
48-
* While largely abstracted, the Angular application inherently becomes tenant-aware through these configured, dynamic URLs.
48+
* While largely abstracted, the Angular application inherently becomes tenant aware through these configured, dynamic URLs.
4949

5050
## 2. Development Environment Strategies for Subdomain Testing
5151

52-
Testing subdomain-based multi-tenancy locally requires a few extra steps compared to path-based tenancy or using the tenant switch dialog.
52+
Testing subdomain based multi tenancy locally requires a few extra steps compared to path based tenancy or using the tenant switch dialog.
5353

5454
### Using the `hosts` File
5555

@@ -77,7 +77,7 @@ Testing subdomain-based multi-tenancy locally requires a few extra steps compare
7777

7878
* Standard `localhost` development certificates provided by `dotnet dev-certs https` will not be valid for custom local subdomains like `tenant1.localhost`. This will result in browser SSL warnings.
7979
* **Solutions:**
80-
1. **HTTP Locally:** For simplicity, you can develop and test the subdomain logic using HTTP locally and rely on the tenant switch dialog if HTTPS-specific features are not being tested.
80+
1. **HTTP Locally:** For simplicity, you can develop and test the subdomain logic using HTTP locally and rely on the tenant switch dialog if HTTPS specific features are not being tested.
8181
2. **`mkcert` Tool:** Use a tool like `mkcert` to create a locally trusted Certificate Authority (CA) and then generate wildcard certificates (e.g., `*.localhost`). You would then configure Kestrel and potentially the Angular dev server to use these certificates. This provides a more accurate simulation of a production HTTPS environment.
8282

8383
### Interaction with Tenant Switch Dialog
@@ -87,37 +87,37 @@ Testing subdomain-based multi-tenancy locally requires a few extra steps compare
8787

8888
## 3. Tenant Resolution Flow Clarification
8989

90-
A clear understanding of the tenant resolution process is essential to ensure accurate tenant identification and proper request routing in a multi-tenant architecture. This step determines which tenant context should be applied based on the incoming request, typically using elements like the subdomain, header, or query string.
90+
A clear understanding of the tenant resolution process is essential to ensure accurate tenant identification and proper request routing in a multi tenant architecture. This step determines which tenant context should be applied based on the incoming request, typically using elements like the subdomain, header, or query string.
9191

9292
### Backend (ASP.NET Core)
9393

9494
1. An incoming HTTP request arrives at the ASP.NET Core application.
9595
2. ASP.NET Zero's middleware, specifically implementations of `ITenantResolveContributor` (like `DomainTenantResolveContributor`), inspects the request's host header (e.g., `tenant1.api.mydomain.com`).
9696
3. If the host matches the configured subdomain pattern (derived from `ServerRootAddress` with the `{TENANCY_NAME}` placeholder), the middleware extracts the tenancy name (`tenant1` in this example).
9797
4. It then attempts to find this tenant in the database.
98-
5. If found, the current tenant context is set for the duration of that request, ensuring data isolation and that tenant-specific settings and services are used.
98+
5. If found, the current tenant context is set for the duration of that request, ensuring data isolation and that tenant specific settings and services are used.
9999

100100
### Frontend (Angular)
101101

102102
1. The Angular application is loaded from a URL like `https://tenant1.app.mydomain.com`.
103103
2. The `ServerRootAddress` in `appsettings.json` (e.g., `https://{TENANCY_NAME}.api.mydomain.com`) is used by the generated service proxies.
104-
3. ASP.NET Zero's client-side JavaScript utilities dynamically replace the `{TENANCY_NAME}` placeholder in `ServerRootAddress` with the actual tenancy name extracted from the current browser window's hostname (`tenant1.app.mydomain.com`).
105-
4. All subsequent API calls made through these service proxies will correctly target the tenant-specific backend API endpoints (e.g., `https://tenant1.api.mydomain.com/api/services/app/User/GetUsers`).
104+
3. ASP.NET Zero's client side JavaScript utilities dynamically replace the `{TENANCY_NAME}` placeholder in `ServerRootAddress` with the actual tenancy name extracted from the current browser window's hostname (`tenant1.app.mydomain.com`).
105+
4. All subsequent API calls made through these service proxies will correctly target the tenant specific backend API endpoints (e.g., `https://tenant1.api.mydomain.com/api/services/app/User/GetUsers`).
106106

107-
## 4. Troubleshooting Common Subdomain Multi-Tenancy Issues
107+
## 4. Troubleshooting Common Subdomain Multi Tenancy Issues
108108

109109
Here are some common problems and how to address them:
110110

111111
### DNS Not Resolving
112112

113113
* **Propagation Time:** DNS changes (especially for new wildcard records) can take time to propagate globally (minutes to hours).
114-
* **Record Verification:** Double-check your DNS provider's settings. Ensure the `A` record or `CNAME` record for the wildcard (e.g., `*.mydomain.com`) correctly points to your web server's public IP address.
114+
* **Record Verification:** Double check your DNS provider's settings. Ensure the `A` record or `CNAME` record for the wildcard (e.g., `*.mydomain.com`) correctly points to your web server's public IP address.
115115
* **Local `hosts` File:** For local development, ensure your `hosts` file entries are correctly spelled, saved, and that your browser or OS is not caching old DNS lookups aggressively (try clearing cache or an incognito window).
116116

117117
### CORS Errors
118118

119119
* **CorsOrigins Configuration:** In the `appsettings.json` of your `*.Web.Host` project, meticulously check the `App:CorsOrigins` setting. It must accurately include the URLs of your Angular application, including the wildcard for subdomains.
120-
* Example: `"CorsOrigins": "https://*.app.mydomain.com,http://*.app.mydomain.com"` (include both HTTP and HTTPS if applicable, and consider ports if non-standard).
120+
* Example: `"CorsOrigins": "https://*.app.mydomain.com,http://*.app.mydomain.com"` (include both HTTP and HTTPS if applicable, and consider ports if non standard).
121121
* **Browser Console:** Always inspect the browser's developer console (Network tab) for detailed CORS error messages. The error often indicates which origin is being blocked and what headers are missing or mismatched from the preflight (OPTIONS) request.
122122
* **Scheme and Port:** CORS is sensitive to scheme (HTTP vs. HTTPS) and port numbers. Ensure these match exactly in your `CorsOrigins` configuration.
123123

@@ -127,7 +127,7 @@ Here are some common problems and how to address them:
127127
* Ensure your certificate is a true wildcard (e.g., `*.mydomain.com`) or a SAN certificate that explicitly lists all required tenant subdomains or the relevant wildcard.
128128
* **Untrusted Certificate:**
129129
* For production, ensure your certificate is issued by a reputable CA.
130-
* For local development with self-signed or `mkcert`-generated certificates, ensure the root CA certificate used to sign them is trusted by your operating system and browser.
130+
* For local development with self signed or `mkcert` generated certificates, ensure the root CA certificate used to sign them is trusted by your operating system and browser.
131131
* **Mixed Content:** Ensure all resources are loaded over HTTPS if your site is HTTPS.
132132

133133
### Incorrect Tenant Loaded or Redirected to Host

0 commit comments

Comments
 (0)