可以从网站访问Azure表吗 [英] Can Azure Table be accessed from Web Site
问题描述
我从部署到Azure的Web-api MVC网站遇到错误500. WebApi控制器访问Azure表存储,并且在本地工作(本地网站与我的Azure表一起工作).
I am experiencing error 500 from the web-api MVC website deployed to Azure. WebApi controllers access Azure Table Storage and it works locally (local website works with my Azure Table).
对问题进行故障排除我使用链接的资源"页面将网站链接到存储,但注意到以下情况: "Windows Azure管理门户的客户预览版不支持将存储帐户链接到网站或云服务" 尽管显示了此消息,但状态显示为已链接".
Troubleshooting the problem I used "Linked Resources" page to link the website to the Storage but noticed the following: "The Customer Preview Release of the Windows Azure Management Portal does not support linking a storage account to a web site or a cloud service" Despite this message it shows status as "Linked".
在Azure的此阶段是否可以从网站访问表?
Is it possible on this stage of Azure to access Table from the Web Sites?
注意:这是VS2010和.net4
Note: It is VS2010 and .net4
根据要求输入代码:
public static TableServiceContext GetContext()
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=AccountName;AccountKey=@cc0untKey==");
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
var context = tableClient.GetDataServiceContext();
сontext.IgnoreResourceNotFoundException = true;
return context;
}
public IEnumerable<Destination> GetAllDestinations()
{
try
{
return TableProvider.GetContext()
.CreateQuery<Destination>(Model.Consts.DestinationTableName);
}
catch (Exception e)
{
return new Destination[1]
{
new Destination()
{
CountryName = e.Message
}
};
}
}
推荐答案
项目创建错误. 当您要使用Web API创建网站时,应选择 Web-> MVC 4 ,而不要选择Cloud-> MVC 4 Web角色.我误以为是第二,然后发布了网站,而不是网站角色.
Project has been create in a wrong way. When you want to create a web site with web api you should choose Web -> MVC 4 and not Cloud -> MVC 4 Web role. By mistake I did second and then published the web site and not a web role.
这篇关于可以从网站访问Azure表吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!