{"id":5435,"date":"2017-03-15T11:30:11","date_gmt":"2017-03-15T15:30:11","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/azuregov\/?p=5435"},"modified":"2017-03-15T11:30:11","modified_gmt":"2017-03-15T15:30:11","slug":"getting-started-with-storage-in-azure-government","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/azuregov\/getting-started-with-storage-in-azure-government\/","title":{"rendered":"Getting Started with Storage in Azure Government"},"content":{"rendered":"<p>Azure Government uses the same underlying technologies as commercial Azure, enabling you to use the development tools you\u2019re already familiar with. However, Azure Government provides a physical and network-isolated instance of Azure which results in a higher level of compliance and security. As a result of this, we use <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/azure-government\/documentation-government-developer-guide#endpoint-mapping\">different physical endpoints<\/a> for our services such as Azure Storage. Getting started with Storage on Azure Government is quite easy.<\/p>\n<p>The <a href=\"http:\/\/storageexplorer.com\/\">Microsoft Azure Storage Explorer<\/a> has quickly become one of the most popular tools for working with Azure Storage. It is cross-platform and free. We are happy to announce the accessibility of Azure Government through the Azure Storage Explorer as of the 0.8.9 release. Government customers will now be able to take advantage of all the latest features of the Azure Storage Explorer such as being able to create and manage blobs, queues, tables, and file shares.<\/p>\n<p>When you open the Azure Storage Explorer desktop application it will ask you how you want to connect to your storage account. The newest version will now give you the option to add an \u201cAzure US Government\u201d account:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azuregov\/\"><img decoding=\"async\" width=\"622\" height=\"545\" class=\"aligncenter size-full wp-image-5465\" alt=\"1\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/146.png\" \/><\/a><\/p>\n<p>Once you\u2019re logged in, the Azure Storage Explorer enables you to quickly and easily see the resources inside your storage account. In the screenshot below, you can see my storage account named \u201csamplegovstorageacct\u201d which has a blob container, a storage queue, and a storage table called \u201cContacts\u201d. With a quick double-click, we can see the contents of our Contacts table:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azuregov\/\"><img decoding=\"async\" width=\"1312\" height=\"761\" class=\"aligncenter size-full wp-image-5455\" alt=\"2\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/226.png\" \/><\/a><\/p>\n<p>Check out the full list of features and download the latest version of the Microsoft Azure Storage Explorer on their home page <a href=\"http:\/\/storageexplorer.com\/\">here<\/a>.<\/p>\n<p>The Azure Storage Explorer is great for quickly connecting to your storage accounts. However, for the keen observers, you noticed that in the last screenshot the URL for our storage looked a little different than the URL for storage in commercial Azure \u2013 specifically, the domain ended with \u201ccore.usgovcloudapi.net\u201d, rather than \u201ccore.windows.net\u201d. These endpoint differences must be taken into account when you connect to storage in Azure Government with C#.<\/p>\n<p>Let see this in action. First, let\u2019s go to the Azure Government portal and select our \u201csamplegovstorageacct\u201d and then click the \u201cAccess Keys\u201d tab:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/azuregov\/\"><img decoding=\"async\" width=\"1235\" height=\"425\" class=\"aligncenter size-full wp-image-5445\" alt=\"3\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/318.png\" \/><\/a><\/p>\n<p>From here we can copy\/paste the storage account name and key. For the simplicity of the sample code, I\u2019ll just paste them into variables \u2013 but these values can be stored in <a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/key-vault\/\">Azure Key Vault<\/a> (which is <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/azure-government\/documentation-government-services#security--identitydocumentation-government-services-securityandidentitymd\">available on Azure Government<\/a>) for maximum security.<\/p>\n<p>Next let\u2019s create a new project in Visual Studio and add a reference to the <a href=\"https:\/\/www.nuget.org\/packages\/WindowsAzure.Storage\/\">WindowsAzure.Storage NuGet package<\/a>. This NuGet package contains classes we will need to connect.<\/p>\n<p>Now it\u2019s just a simple matter of 2 lines of C# code to connect:<\/p>\n<table class=\"table table-bordered table-condensed\" style=\"width: 583.59px\">\n<tbody>\n<tr>\n<td style=\"width: 723px\">var credentials = new StorageCredentials(storageAccountName, storageAccountKey);<\/p>\n<p>var storageAccount = new CloudStorageAccount(credentials, &#8220;core.usgovcloudapi.net&#8221;, useHttps: true);<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Notice on the second line we had to use a <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/azure\/dn451950.aspx\">particular constructor for the CloudStorageAccount<\/a> \u2013 enabling us to explicitly pass in the endpoint suffix of \u201ccore.usgovcloudapi.net\u201d. This constructor is the <strong><u>only<\/u><\/strong> difference your code requires to connect to storage in Azure Government as compared with commercial Azure.<\/p>\n<p>At this point, we can interact with storage as we normally would. For example, if we want to retrieve a specific record from our table storage we could do it like this:<\/p>\n<table class=\"table table-bordered table-condensed\" style=\"width: 763px\">\n<tbody>\n<tr>\n<td style=\"width: 757px\">var tableClient = storageAccount.CreateCloudTableClient();<\/p>\n<p>var table = tableClient.GetTableReference(&#8220;Contacts&#8221;);<\/p>\n<p>var retrieveOperation = TableOperation.Retrieve&lt;ContactEntity&gt;(&#8220;gov-partition1&#8221;, &#8220;0fb52a6c-3784-4dc5-aa6d-ecda4426dbda&#8221;);<\/p>\n<p>var result = await table.ExecuteAsync(retrieveOperation);<\/p>\n<p>var contact = result.Result as ContactEntity;<\/p>\n<p>Console.WriteLine($&#8221;Contact: {contact.FirstName} {contact.LastName}&#8221;);<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>We welcome your comments and suggestions to help us continually improve your Azure Government experience. To stay up to date on all things Azure Government, be sure to subscribe to our <a href=\"https:\/\/blogs.msdn.microsoft.com\/azuregov\/feed\/\">RSS feed<\/a> and to receive emails, click \u201cSubscribe by Email!\u201d on the <a href=\"https:\/\/blogs.msdn.microsoft.com\/azuregov\/\">Azure Government Blog<\/a>. To experience the power of Azure Government for your organization, sign up for an <a href=\"https:\/\/azuregov.microsoft.com\/trial\/azuregovtrial\">Azure Government Trial<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Azure Government uses the same underlying technologies as commercial Azure, enabling you to use the development tools you\u2019re already familiar with. However, Azure Government provides a physical and network-isolated instance of Azure which results in a higher level of compliance and security. As a result of this, we use different physical endpoints for our services [&hellip;]<\/p>\n","protected":false},"author":1789,"featured_media":20423,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2,1,21,25,30],"tags":[75,95,311,531],"class_list":["post-5435","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-announcements","category-azuregov","category-onboarding","category-portalpreview","category-storage-backup-recovery","tag-azure","tag-azure-government","tag-getting-started","tag-storage"],"acf":[],"blog_post_summary":"<p>Azure Government uses the same underlying technologies as commercial Azure, enabling you to use the development tools you\u2019re already familiar with. However, Azure Government provides a physical and network-isolated instance of Azure which results in a higher level of compliance and security. As a result of this, we use different physical endpoints for our services [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/posts\/5435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/users\/1789"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/comments?post=5435"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/posts\/5435\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/media\/20423"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/media?parent=5435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/categories?post=5435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/tags?post=5435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}