我想调试 WebApi 客户端项目。
客户端示例来自 Azure,可供使用。我通过更改显示的行将其配置为使用本地 WebAPI 后端
var client = new WindowsAzure.MobileServiceClient('https://myproject-code.azurewebsites.net', 'https://someGateWay.azurewebsites.net', '');
至
var client = new WindowsAzure.MobileServiceClient('http://localhost:59477/', '', '');
如您所见,API 在端口 59477 上运行。当我刷新客户端(端口 4400)时,它查询 API 并遇到 CORS 异常:
No 'Access-Control-Allow-Origin' header is present on the requested resource
如何设置它以在本地开发和调试服务器和客户端?
最佳答案
我还没有尝试过这个,因为我通常在我的移动应用程序中使用 JavaScript 后端,但您只需要告诉移动应用程序允许 localhost 通过 CORS 访问它。这篇文章关于Azure Mobile Services .NET Adds CORS Support, Better Authentication应该可以带你到达那里。
关于javascript - 将 Azure MobileServiceClient 与本地后端连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31639527/