[英]how to use “Users” feature in Azure Mobile Service .NET backend
[英]cors not working with azure mobile service .net backend
我们遇到了权限问题,无论浏览什么页面,似乎都无法正常运行。 我们分为两个部分。 Azure和网页(客户端)中的移动服务。 Web服务称为“ https://mobileservice.azure-mobile.net/tables/program ....”,客户端网页称为“ http://azure-webservicesclient.azurewebsites.net ”。
我们在“ https://mobileservice.azure-mobile.net ”上启用了
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
<system.webServer>
但这似乎不起作用,它仍然会给出错误:404(未找到)在请求的源上不存在access-control-allow-origin'标头。 我们还遵循了教程“ http://www.codeguru.com/csharp/.net/net_asp/using-cross-origin-resource-sharing-cors-in-asp.net-web-api.html ”,但结果相同。
请在这里查看我们的代码,任何人有什么想法吗?
<!-- WinJS code -->
<script src='http://ajax.aspnetcdn.com/ajax/mobileservices/MobileServices.Web-1.1.2.min.js'></script>
<script>
$(function () {var client = new WindowsAzure.MobileServiceClient('https://mobileservice.azure-mobile.net/', '*****KEY********'),
todoItemTable = client.getTable('program');
console.log(todoItemTable.read());
// Read current data and rebuild UI.
// If you plan to generate complex UIs like this, consider using a JavaScript templating library.
function refreshTodoItems() {
var query = todoItemTable.where({ id_program: 21 });
query.read().then(function (todoItems) {
//var listItems = $.map(todoItems, function (item) {
// return $('<li>')
// .attr('data-todoitem-id', item.id)
// .append($('<button class="item-delete">Delete</button>'))
// .append($('<div>').append($('<input class="item-text">').val(item.text)));
//});
console.log(todoItems);
//$('#todo-items').empty().append(listItems).toggle(listItems.length > 0);
//$('#summary').html('<strong>' + todoItems.length + '</strong> item(s)');
}, handleError);
}
// On initial load, start by fetching the current data
// refreshTodoItems();
});
</script>
要为Azure移动服务启用CORS,请使用ASP.NET Web API CORS NuGet包:
http://www.nuget.org/packages/Microsoft.AspNet.WebApi.Cors/5.1.2
目前,您必须使用以下技巧启用它:
https://gist.github.com/HenrikFrystykNielsen/6c934be6c6c8fa9e4bc8
我们很快将为CORS提供内置支持,因此您不必自己启用它。
希望这可以帮助,
亨里克
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.