[英]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.