我是 ASP.NET 的新手,休息...
我只是在制作一个 web 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();
}
但抛出错误。看来这不是这样的方法。请你能帮我推荐一个好的教程或解决这个问题......这将非常有帮助。