启动应用程序时发生错误

时间:2019-05-20 09:33:23

标签: asp.net asp.net-web-api azure-cosmosdb asp.net-core-2.1 asp.net-core-webapi-2.1

我用cosmos db开发了一个Web API。 full code link

我遇到以下错误。 enter image description here

请帮助我找出我在做错什么。

2 个答案:

答案 0 :(得分:1)

1-确保您拥有正确的端点和键

2-在cosmosDB帐户刀片中->防火墙和虚拟网络->确保您允许托管您的应用的服务器的IP访问cosmos帐户,如果您的Web应用处于天蓝色,请检查选项[接受来自公共天蓝色数据中心内的连接]

在DocumentDbRepository中只是关于此代码的旁注 要获得更好的代码,只需使用

s_trim

而不是使用您正在使用的那个 https://github.com/kajasumanie/calalogapi/blob/master/CalalogAPI/DocumentDBRepository.cs第33行 这段代码需要一些重构

答案 1 :(得分:1)

从错误开始,看来您的cosmosdb帐户uri错误。确保有一个有意义的网址,而不是带有id的网址,

类似

https://psdemo-cosmosdb.documents.azure.com:443/

而不是带有小数的东西(因为很难解析)

也不要将您的秘密密钥推送到您的仓库中。

我发现问题出在line

 Document document = await client.ReadDocumentAsync(UriFactory.CreateDocumentUri(DatabaseId, collectionId, id));

查询数据时需要传递partitionKey。

相关问题