Skip to content

Commit 0d59403

Browse files
Combine SAS articles for containers and blobs
1 parent 93f8d80 commit 0d59403

File tree

2 files changed

+69
-11
lines changed

2 files changed

+69
-11
lines changed

articles/storage/blobs/sas-service-create-dotnet.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,68 @@
11
---
22
title: Create a service SAS for a blob with .NET
33
titleSuffix: Azure Storage
4-
description: Learn how to create a service shared access signature (SAS) for a blob using the Azure Blob Storage client library for .NET.
4+
description: Learn how to create a service shared access signature (SAS) for a container or blob using the Azure Blob Storage client library for .NET.
55
author: pauljewellmsft
66

77
ms.service: azure-blob-storage
88
ms.topic: how-to
9-
ms.date: 08/05/2024
9+
ms.date: 09/06/2024
1010
ms.author: pauljewell
1111
ms.reviewer: nachakra
1212
ms.devlang: csharp
1313
ms.custom: devx-track-csharp, devguide-csharp, engagement-fy23, devx-track-dotnet
1414
---
1515

16-
# Create a service SAS for a blob with .NET
16+
# Create a service SAS for a container or blob with .NET
1717

1818
[!INCLUDE [storage-dev-guide-selector-service-sas](../../../includes/storage-dev-guides/storage-dev-guide-selector-service-sas.md)]
1919

2020
[!INCLUDE [storage-auth-sas-intro-include](../../../includes/storage-auth-sas-intro-include.md)]
2121

22-
This article shows how to use the storage account key to create a service SAS for a blob with the Azure Blob Storage client library for .NET.
22+
This article shows how to use the storage account key to create a service SAS for a container or blob with the Azure Blob Storage client library for .NET.
2323

2424
## About the service SAS
2525

2626
A service SAS is signed with the account access key. You can use the [StorageSharedKeyCredential](/dotnet/api/azure.storage.storagesharedkeycredential) class to create the credential that is used to sign the service SAS.
2727

2828
You can also use a stored access policy to define the permissions and duration of the SAS. If the name of an existing stored access policy is provided, that policy is associated with the SAS. To learn more about stored access policies, see [Define a stored access policy](#define-a-stored-access-policy). If no stored access policy is provided, the code examples in this article show how to define permissions and duration for the SAS.
2929

30-
## Create a service SAS for a blob
30+
## Create a service SAS
31+
32+
You can create a service SAS for a container or blob, based on the needs of your app.
33+
34+
### [Container](#tab/container)
35+
36+
The following code example shows how to create a service SAS for a container resource. First, the code verifies that the [BlobContainerClient](/dotnet/api/azure.storage.blobs.blobcontainerclient) object is authorized with a shared key credential by checking the [CanGenerateSasUri](/dotnet/api/azure.storage.blobs.blobcontainerclient.cangeneratesasuri) property. Then, it generates the service SAS via the [BlobSasBuilder](/dotnet/api/azure.storage.sas.blobsasbuilder) class, and calls [GenerateSasUri](/dotnet/api/azure.storage.blobs.blobcontainerclient.generatesasuri) to create a service SAS URI based on the client and builder objects.
37+
38+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/CreateSas.cs" id="Snippet_CreateServiceSASContainer":::
39+
40+
### [Blob](#tab/blob)
3141

3242
The following code example shows how to create a service SAS for a blob resource. First, the code verifies that the [BlobClient](/dotnet/api/azure.storage.blobs.blobclient) object is authorized with a shared key credential by checking the [CanGenerateSasUri](/dotnet/api/azure.storage.blobs.specialized.blobbaseclient.cangeneratesasuri#azure-storage-blobs-specialized-blobbaseclient-cangeneratesasuri) property. Then, it generates the service SAS via the [BlobSasBuilder](/dotnet/api/azure.storage.sas.blobsasbuilder) class, and calls [GenerateSasUri](/dotnet/api/azure.storage.blobs.specialized.blobbaseclient.generatesasuri#azure-storage-blobs-specialized-blobbaseclient-generatesasuri(azure-storage-sas-blobsasbuilder)) to create a service SAS URI based on the client and builder objects.
3343

3444
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/CreateSas.cs" id="Snippet_CreateServiceSASBlob":::
3545

46+
---
47+
3648
## Use a service SAS to authorize a client object
3749

50+
You can use a service SAS to authorize a client object to perform operations on a container or blob based on the permissions granted by the SAS.
51+
52+
### [Container](#tab/container)
53+
54+
The following code examples show how to use the service SAS to authorize a [BlobContainerClient](/dotnet/api/azure.storage.blobs.blobcontainerclient) object. This client object can be used to perform operations on the container resource based on the permissions granted by the SAS.
55+
56+
First, create a [BlobServiceClient](/dotnet/api/azure.storage.blobs.blobserviceclient) object signed with the account access key:
57+
58+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/CreateSas.cs" id="Snippet_CreateServiceClientSharedKey":::
59+
60+
Then, generate the service SAS as shown in the earlier example and use the SAS to authorize a [BlobContainerClient](/dotnet/api/azure.storage.blobs.blobcontainerclient) object:
61+
62+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/CreateSas.cs" id="Snippet_UseServiceSASContainer":::
63+
64+
### [Blob](#tab/blob)
65+
3866
The following code example shows how to use the service SAS to authorize a [BlobClient](/dotnet/api/azure.storage.blobs.blobclient) object. This client object can be used to perform operations on the blob resource based on the permissions granted by the SAS.
3967

4068
First, create a [BlobServiceClient](/dotnet/api/azure.storage.blobs.blobserviceclient) object signed with the account access key:
@@ -45,12 +73,18 @@ Then, generate the service SAS as shown in the earlier example and use the SAS t
4573

4674
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/CreateSas.cs" id="Snippet_UseServiceSASBlob":::
4775

76+
---
77+
4878
[!INCLUDE [storage-dev-guide-stored-access-policy](../../../includes/storage-dev-guides/storage-dev-guide-stored-access-policy.md)]
4979

5080
## Resources
5181

5282
To learn more about creating a service SAS using the Azure Blob Storage client library for .NET, see the following resources.
5383

84+
### Code samples
85+
86+
- [View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/dotnet/BlobDevGuideBlobs/CreateSas.cs)
87+
5488
[!INCLUDE [storage-dev-guide-resources-dotnet](../../../includes/storage-dev-guides/storage-dev-guide-resources-dotnet.md)]
5589

5690
### See also

articles/storage/blobs/storage-blob-user-delegation-sas-create-dotnet.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
---
22
title: Create a user delegation SAS for a blob with .NET
33
titleSuffix: Azure Storage
4-
description: Learn how to create a user delegation SAS for a blob with Microsoft Entra credentials by using the .NET client library for Blob Storage.
4+
description: Learn how to create a user delegation SAS for a container or blob with Microsoft Entra credentials by using the .NET client library for Blob Storage.
55
services: storage
66
author: pauljewellmsft
77
ms.author: pauljewell
88
ms.service: azure-blob-storage
99
ms.topic: how-to
10-
ms.date: 08/05/2024
10+
ms.date: 09/06/2024
1111
ms.reviewer: dineshm
1212
ms.devlang: csharp
1313
ms.custom: devx-track-csharp, devguide-csharp, devx-track-dotnet
1414
---
1515

16-
# Create a user delegation SAS for a blob with .NET
16+
# Create a user delegation SAS for a container or blob with .NET
1717

1818
[!INCLUDE [storage-dev-guide-selector-user-delegation-sas](../../../includes/storage-dev-guides/storage-dev-guide-selector-user-delegation-sas.md)]
1919

2020
[!INCLUDE [storage-auth-sas-intro-include](../../../includes/storage-auth-sas-intro-include.md)]
2121

22-
This article shows how to use Microsoft Entra credentials to create a user delegation SAS for a blob using the [Azure Storage client library for .NET](/dotnet/api/overview/azure/storage).
22+
This article shows how to use Microsoft Entra credentials to create a user delegation SAS for a container or blob using the [Azure Storage client library for .NET](/dotnet/api/overview/azure/storage).
2323

2424
[!INCLUDE [storage-auth-user-delegation-include](../../../includes/storage-auth-user-delegation-include.md)]
2525

@@ -31,12 +31,32 @@ When a Microsoft Entra security principal attempts to access blob data, that sec
3131

3232
## Create a user delegation SAS for a blob
3333

34-
Once you've obtained the user delegation key, you can create a user delegation SAS to delegate limited access to a blob resource. The following code example shows how to create a user delegation SAS for a blob:
34+
You can create a user delegation SAS for a container or blob, based on the needs of your app.
35+
36+
### [Container](#tab/container)
37+
38+
Once you've obtained the user delegation key, you can create a user delegation SAS to delegate limited access to a container. The following code example shows how to create a user delegation SAS for a container:
39+
40+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/CreateSas.cs" id="Snippet_CreateUserDelegationSASContainer":::
41+
42+
### [Blob](#tab/blob)
43+
44+
Once you've obtained the user delegation key, you can create a user delegation SAS to delegate limited access to a blob. The following code example shows how to create a user delegation SAS for a blob:
3545

3646
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/CreateSas.cs" id="Snippet_CreateUserDelegationSASBlob":::
3747

3848
## Use a user delegation SAS to authorize a client object
3949

50+
You can use a user delegation SAS to authorize a client object to perform operations on a container or blob based on the permissions granted by the SAS.
51+
52+
### [Container](#tab/container)
53+
54+
The following code example shows how to use the user delegation SAS to authorize a [BlobContainerClient](/dotnet/api/azure.storage.blobs.blobcontainerclient) object. This client object can be used to perform operations on the container resource based on the permissions granted by the SAS.
55+
56+
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/CreateSas.cs" id="Snippet_UseUserDelegationSASContainer":::
57+
58+
### [Blob](#tab/blob)
59+
4060
The following code example shows how to use the user delegation SAS to authorize a [BlobClient](/dotnet/api/azure.storage.blobs.blobclient) object. This client object can be used to perform operations on the blob resource based on the permissions granted by the SAS.
4161

4262
:::code language="csharp" source="~/azure-storage-snippets/blobs/howto/dotnet/BlobDevGuideBlobs/CreateSas.cs" id="Snippet_UseUserDelegationSASBlob":::
@@ -45,9 +65,13 @@ The following code example shows how to use the user delegation SAS to authorize
4565

4666
To learn more about creating a user delegation SAS using the Azure Blob Storage client library for .NET, see the following resources.
4767

68+
### Code samples
69+
70+
- [View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/dotnet/BlobDevGuideBlobs/CreateSas.cs)
71+
4872
### REST API operations
4973

50-
The Azure SDK for .NET contains libraries that build on top of the Azure REST API, allowing you to interact with REST API operations through familiar .NET paradigms. The client library method for getting a user delegation key uses the following REST API operations:
74+
The Azure SDK for .NET contains libraries that build on top of the Azure REST API, allowing you to interact with REST API operations through familiar .NET paradigms. The client library method for getting a user delegation key uses the following REST API operation:
5175

5276
- [Get User Delegation Key](/rest/api/storageservices/get-user-delegation-key) (REST API)
5377

0 commit comments

Comments
 (0)