Это очень просто, если вы будете следовать этому документ .
У меня есть демо, как показано ниже:
1. В visual studio -> Диспетчер пакетов Nuget установите последнюю версию WindowsAzure.ConfigurationManager
и WindowsAzure.Storage
2.В узле web.config -> appsettings добавьте <add key="StorageConnectionString" value="your storage account string" />
:
3.В своем веб-проекте asp.net добавьте пользовательский класс, производный от 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();
}
- Моя лазурная таблица и результат теста:
все адреса электронной почты отображаются на веб-странице: