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
Copy file name to clipboardExpand all lines: articles/app-service/configure-ssl-certificate-in-code.md
+66-23Lines changed: 66 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: Use SSL certificate in application code - Azure App Service | Microsoft Docs
2
+
title: Use SSL certificate in code - Azure App Service | Microsoft Docs
3
3
description: Learn how to use client certificates to connect to remote resources that require them.
4
4
services: app-service
5
5
documentationcenter:
@@ -11,18 +11,18 @@ ms.service: app-service
11
11
ms.workload: web
12
12
ms.tgt_pltfrm: na
13
13
ms.topic: article
14
-
ms.date: 10/16/2019
14
+
ms.date: 11/04/2019
15
15
ms.author: cephalin
16
16
ms.reviewer: yutlin
17
17
ms.custom: seodec18
18
18
19
19
---
20
20
21
-
# Use an SSL certificate in your application code in Azure App Service
21
+
# Use an SSL certificate in your code in Azure App Service
22
22
23
-
Your App Serviceapp code may act as a client and access an external service that requires certificate authentication. This how-to guide shows how to use public or private certificates in your application code.
23
+
In your application code, you can access the [public or private certificates you add to App Service](configure-ssl-certificate.md). Your app code may act as a client and access an external service that requires certificate authentication, or it may need to perform cryptographic tasks. This how-to guide shows how to use public or private certificates in your application code.
24
24
25
-
This approach to using certificates in your code makes use of the SSL functionality in App Service, which requires your app to be in **Basic** tier or above. Alternatively, you can [include the certificate file in your app repository](#load-certificate-from-file), but it's not a recommended practice for private certificates.
25
+
This approach to using certificates in your code makes use of the SSL functionality in App Service, which requires your app to be in **Basic** tier or above. If your app is in **Free** or **Shared** tier, you can [include the certificate file in your app repository](#load-certificate-from-file).
26
26
27
27
When you let App Service manage your SSL certificates, you can maintain the certificates and your application code separately and safeguard your sensitive data.
28
28
@@ -43,25 +43,24 @@ Find the certificate you want to use and copy the thumbprint.
43
43
44
44

45
45
46
-
## Load the certificate
46
+
## Make the certificate accessible
47
47
48
-
To use a certificate in your app code, add its thumbprint to the `WEBSITE_LOAD_CERTIFICATES` app setting, by running the following command in the <atarget="_blank"href="https://shell.azure.com" >Cloud Shell</a>:
48
+
To access a certificate in your app code, add its thumbprint to the `WEBSITE_LOAD_CERTIFICATES` app setting, by running the following command in the <atarget="_blank"href="https://shell.azure.com" >Cloud Shell</a>:
49
49
50
50
```azurecli-interactive
51
51
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings WEBSITE_LOAD_CERTIFICATES=<comma-separated-certificate-thumbprints>
52
52
```
53
53
54
54
To make all your certificates accessible, set the value to `*`.
55
55
56
-
> [!NOTE]
57
-
> This setting places the specified certificates in the [Current User\My](/windows-hardware/drivers/install/local-machine-and-current-user-certificate-stores) store for most pricing tiers, but in the **Isolated** tier (i.e. app runs in an [App Service Environment](environment/intro.md)), it places the certificates in the [Local Machine\My](/windows-hardware/drivers/install/local-machine-and-current-user-certificate-stores) store.
58
-
>
56
+
## Load certificate in Windows apps
59
57
60
-
The configured certificates are now ready to be used by your code.
58
+
The `WEBSITE_LOAD_CERTIFICATES` app setting makes the specified certificates accessible to your Windows hosted app in the Windows certificate store, and the location depends on the [pricing tier](overview-hosting-plans.md):
61
59
62
-
## Load the certificate in code
60
+
-**Isolated** tier - in [Local Machine\My](/windows-hardware/drivers/install/local-machine-and-current-user-certificate-stores).
61
+
- All other tiers - in [Current User\My](/windows-hardware/drivers/install/local-machine-and-current-user-certificate-stores).
63
62
64
-
Once your certificate is accessible, you access it in C# code by the certificate thumbprint. The following code loads a certificate with the thumbprint `E661583E8FABEF4C0BEF694CBC41C28FB81CD870`.
63
+
In C# code, you access the certificate by the certificate thumbprint. The following code loads a certificate with the thumbprint `E661583E8FABEF4C0BEF694CBC41C28FB81CD870`.
65
64
66
65
```csharp
67
66
usingSystem;
@@ -86,31 +85,75 @@ certStore.Close();
86
85
...
87
86
```
88
87
89
-
<aname="file"></a>
90
-
## Load certificate from file
88
+
In Java code, you access the certificate from the "Windows-MY" store using the Subject Common Name field (see [Public key certificate](https://en.wikipedia.org/wiki/Public_key_certificate)). The following code shows how to load a private key certificate:
91
89
92
-
If you need to load a certificate file from your application directory, it's better to upload it using [FTPS](deploy-ftp.md) instead of [Git](deploy-local-git.md), for example. You should keep sensitive data like a private certificate out of source control.
Even though you're loading the file directly in your .NET code, the library still verifies if the current user profile is loaded. To load the current user profile, set the `WEBSITE_LOAD_USER_PROFILE` app setting with the following command in the <atarget="_blank"href="https://shell.azure.com" >Cloud Shell</a>.
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings WEBSITE_LOAD_USER_PROFILE=1
103
+
// Use the certificate and key
104
+
...
98
105
```
99
106
100
-
Once this setting is set, the following C# example loads a certificate called `mycert.pfx` from the `certs` directory of your app's repository.
107
+
For languages that don't support or offer insufficient support for the Windows certificate store, see [Load certificate from file](#load-certificate-from-file).
108
+
109
+
## Load certificate in Linux apps
110
+
111
+
The `WEBSITE_LOAD_CERTIFICATES` app settings makes the specified certificates accessible to your Linux hosted apps (including custom container apps) as files. The files are found under the following directories:
To see how to load an SSL certificate from a file in Node.js, PHP, Python, Java, or Ruby, see the documentation for the respective language or web platform.
130
+
131
+
## Load certificate from file
132
+
133
+
If you need to load a certificate file that you upload manually, it's better to upload the certificate using [FTPS](deploy-ftp.md) instead of [Git](deploy-local-git.md), for example. You should keep sensitive data like a private certificate out of source control.
134
+
135
+
> [!NOTE]
136
+
> ASP.NET and ASP.NET Core on Windows must access the certificate store even if you load a certificate from a file. To load a certificate file in a Windows .NET app, load the current user profile with the following command in the <atarget="_blank"href="https://shell.azure.com" >Cloud Shell</a>:
137
+
>
138
+
> ```azurecli-interactive
139
+
> az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings WEBSITE_LOAD_USER_PROFILE=1
140
+
> ```
141
+
142
+
The following C# example loads a public certificate from a relative path in your app:
143
+
144
+
```csharp
145
+
using System;
146
+
using System.Security.Cryptography.X509Certificates;
var bytes = System.IO.File.ReadAllBytes("~/<relative-path-to-cert-file>");
150
+
var cert = new X509Certificate2(bytes);
151
+
152
+
// Use the loaded certificate
112
153
```
113
154
155
+
To see how to load an SSL certificate from a file in Node.js, PHP, Python, Java, or Ruby, see the documentation for the respective language or web platform.
156
+
114
157
## More resources
115
158
116
159
*[Secure a custom DNS name with an SSL binding](configure-ssl-bindings.md)
Copy file name to clipboardExpand all lines: articles/app-service/configure-ssl-certificate.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,6 +60,7 @@ To secure a custom domain in an SSL binding, the certificate has additional requ
60
60
61
61
The free App Service Managed Certificate is a turn-key solution for securing your custom DNS name in App Service. It's a fully functional SSL certificate that's managed by App Service and renewed automatically. The free certificate comes with the following limitations:
62
62
63
+
- Does not support wildcard certificates.
63
64
- Does not support naked domains.
64
65
- Is not exportable.
65
66
@@ -276,7 +277,7 @@ Click **Upload**.
276
277
277
278

278
279
279
-
Once the certificate is uploaded, copy the certificate thumbprint and see [Make the certificate accessible](configure-ssl-certificate-in-code.md#load-the-certificate).
280
+
Once the certificate is uploaded, copy the certificate thumbprint and see [Make the certificate accessible](configure-ssl-certificate-in-code.md#make-the-certificate-accessible).
0 commit comments