[英]Using Azure blob storage with .NET
嗨,我正在嘗試學習如何使用 Azure 和 .Net。
我構建了一個簡單的“Hello World”webApp 並創建了一個 Blob 存儲,其中包含一個包含 3 個電子郵件地址的表(當然,webApp 和 Blob 存儲在同一訂閱下)
我想要做的就是在運行網站時顯示這 3 個電子郵件地址。 即從 blob 存儲中的表中獲取此地址列表並將其呈現在網站上。
我不知道從哪里開始,微軟的教程也沒有多大幫助。
在我的 WebApp 下的解決方案資源管理器中,有一個文件夾“Controllers”。 我的直覺是在那里開設一個新課程,但我又不知道如何開始。
如果您遵循此文檔,這將非常簡單。
我有一個演示如下:
1.在visual studio -> Nuget Package Manager,安裝最新版本的WindowsAzure.ConfigurationManager
和WindowsAzure.Storage
2.在 web.config -> appsettings 節點中,添加<add key="StorageConnectionString" value="your storage account string" />
:
3.在你的asp.net web項目中,添加一個派生自TableEntity的自定義類:
public class CustomerEntity : TableEntity
{
public CustomerEntity(string lastName, string firstName)
{
this.PartitionKey = lastName;
this.RowKey = firstName;
}
public CustomerEntity() { }
public string Email { get; set; }
public string PhoneNumber { get; set; }
}
4.然后在您的控制器中,添加以下代碼(我在 Contact 方法中添加了代碼):
using System.Web.Mvc;
using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
public ActionResult Contact()
{
//define the emails to output in web page
string emails = "";
// Retrieve the storage account from the connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the table client.
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
// Create the CloudTable object that represents the "people" table.
CloudTable table = tableClient.GetTableReference("people");
TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>();
foreach (CustomerEntity entity in table.ExecuteQuery(query))
{
emails += entity.Email+";";
}
ViewBag.Message = "Your contact page."+emails;
return View();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.