You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -158,7 +158,7 @@ Next, you enable the built-in CORS support in App Service for your API.
158
158
159
159

160
160
161
-
Because of the domain mismatch between the browser app (`http://localhost:5000`) and remote resource (`http://<app_name>.azurewebsites.net`), and the fact that your API in App Service is not sending the `Access-Control-Allow-Origin` header, your browser has prevented cross-domain content from loading in your browser app.
161
+
The domain mismatch between the browser app (`http://localhost:5000`) and remote resource (`http://<app_name>.azurewebsites.net`) is recognized by your browser as a cross-origin resource request. Also, the fact that your REST API the App Service app is not sending the `Access-Control-Allow-Origin` header, the browser has prevented cross-domain content from loading.
162
162
163
163
In production, your browser app would have a public URL instead of the localhost URL, but the way to enable CORS to a localhost URL is the same as a public URL.
164
164
@@ -170,13 +170,7 @@ In the Cloud Shell, enable CORS to your client's URL by using the [`az webapp co
170
170
az webapp cors add --resource-group myResourceGroup --name <app-name> --allowed-origins 'http://localhost:5000'
171
171
```
172
172
173
-
You can set more than one client URL in`properties.cors.allowedOrigins` (`"['URL1','URL2',...]"`). You can also enable all client URLs with `"['*']"`.
174
-
175
-
> [!NOTE]
176
-
> If your app requires credentials such as cookies or authentication tokens to be sent, the browser may require the `ACCESS-CONTROL-ALLOW-CREDENTIALS` header on the response. To enable this in App Service, set`properties.cors.supportCredentials` to `true`in your CORS config. This cannot be enabled when `allowedOrigins` includes `'*'`.
177
-
178
-
> [!NOTE]
179
-
> Specifying `AllowAnyOrigin` and `AllowCredentials` is an insecure configuration and can result in cross-site request forgery. The CORS service returns an invalid CORS response when an app is configured with both methods.
173
+
You can add multiple allowed origins by running the command multiple times or by adding a comma-separate list in`--allowed-origins`. To allow all origins, use `--allowed-origins '*'`.
180
174
181
175
### Test CORS again
182
176
@@ -186,7 +180,13 @@ Refresh the browser app at `http://localhost:5000`. The error message in the **C
186
180
187
181
Congratulations, you're running an API in Azure App Service with CORS support.
188
182
189
-
## App Service CORS vs. your CORS
183
+
## Frequently asked questions
184
+
185
+
- [App Service CORS vs. your CORS](#app-service-cors-vs-your-cors)
186
+
- [How do I set allowed origins to a wildcard subdomain?](#how-do-i-set-allowed-origins-to-a-wildcard-subdomain)
187
+
- [How do I enable the ACCESS-CONTROL-ALLOW-CREDENTIALS header on the response?](#how-do-i-enable-the-access-control-allow-credentials-header-on-the-response)
188
+
189
+
#### App Service CORS vs. your CORS
190
190
191
191
You can use your own CORS utilities instead of App Service CORS for more flexibility. For example, you may want to specify different allowed origins for different routes or methods. Since App Service CORS lets you specify one set of accepted origins for all API routes and methods, you would want to use your own CORS code. See how ASP.NET Core does it at [Enabling Cross-Origin Requests (CORS)](/aspnet/core/security/cors).
192
192
@@ -197,6 +197,26 @@ The built-in App Service CORS feature does not have options to allow only specif
197
197
>
198
198
>
199
199
200
+
#### How do I set allowed origins to a wildcard subdomain?
201
+
202
+
A wildcard subdomain like `*.contoso.com` is more restrictive than the wildcard origin `*`. However, the app's CORS management page in the Azure portal doesn't let you set a wildcard subdomain as an allowed origin. However, you can do it using the Azure CLI, like so:
203
+
204
+
```azurecli-interactive
205
+
az webapp cors add --resource-group <group-name> --name <app-name> --allowed-origins 'https://*.contoso.com'
206
+
```
207
+
208
+
#### How do I enable the ACCESS-CONTROL-ALLOW-CREDENTIALS header on the response?
209
+
210
+
If your app requires credentials such as cookies or authentication tokens to be sent, the browser may require the `ACCESS-CONTROL-ALLOW-CREDENTIALS` header on the response. To enable this in App Service, set`properties.cors.supportCredentials` to `true`.
211
+
212
+
```azurecli-interactive
213
+
az resource update --name web --resource-group <group-name> \
This operation is not allowed when allowed origins include the wildcard origin `'*'`. Specifying `AllowAnyOrigin` and `AllowCredentials` is an insecure configuration and can result in cross-site request forgery. To allow credentials, try replacing the wildcard origin with [wildcard subdomains](#how-do-i-set-allowed-origins-to-a-wildcard-subdomain).
0 commit comments