1
我新的ASP.NET和休息...授權的Web API在asp.net MVC
我只是在做一個網站API2我的REST服務器已經準備就緒,並客戶端準備。
該API必須僅由有效用戶使用用戶名和密碼訪問。因此,它需要檢查的有效用戶,所以我試圖訪問用戶:
var uri = 'http://localhost/ProductsApp/api/products/username/password';
$(document).ready(function() {
// Send an AJAX request
$.getJSON(uri)
.done(function (data) {
// On success, 'data' contains a list of products.
$.each(data, function (key, item) {
// Add a list item for the product.
$('<li>', { text: formatItem(item) }).appendTo($('#products'));
});
});
});
並就稱它爲訪問下面的方法:
public IEnumerable<Clients> GetAllClients(string username, string password)
{
//Here i tried to check the username and password
HttpRequestMessage message = new HttpRequestMessage();
message.GetClientCertificate();
return dbContext.Clients.ToList();
}
但拋出錯誤。看來這不是這樣的方法。請你幫我介紹一個好的教程或解決這個問題......這將是非常有幫助的。