Asp.net 如何为Web API GET请求指定用户名和密码
ASP.NET MVC4 WebAPI应用程序对WebAPI使用表单身份验证:Asp.net 如何为Web API GET请求指定用户名和密码,asp.net,asp.net-mvc,asp.net-mvc-4,asp.net-web-api,forms-authentication,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Asp.net Web Api,Forms Authentication,ASP.NET MVC4 WebAPI应用程序对WebAPI使用表单身份验证: [Authorize] public class EntityController : APIBase { public HttpResponseMessage Get(string id, string _sidx = null, string _sord = null, uint _page = 1, uint _rows = 100,
[Authorize]
public class EntityController : APIBase
{
public HttpResponseMessage Get(string id,
string _sidx = null,
string _sord = null,
uint _page = 1,
uint _rows = 100,
string _filters = null,
int? _dokumnr = null,
int? _vmnr = null,
string _isik = null,
uint _npage = 1,
bool _unpaid = false,
uint _layout = 0,
string _culture = null
)
{
....
这需要传递身份验证cookie。
如何允许从浏览器url调用Get()方法
可以使用在URL中指定用户名和密码
http:://user:pass@mysite.com/API/Entity/Customer
或作为查询字符串
http:://mysite.com/API/Entity/Customer?user=myuser&password=mypass
如何在API控制器中获取用户和密码,并像Authorize属性一样使用表单身份验证通过验证这些凭据登录
或者有没有更好的方法从浏览器url“”调用此API方法?首先,您应该使用ViewModels,因为您的操作有很多参数,并且出于安全原因,您不应该通过querystring传递用户名和密码。如果您有更具体的场景,您可以创建自己的
[Authorize]
过滤器,并将验证逻辑放在其中。您的身份验证信息将通过请求头到达服务器。我完全理解,您正在调用Web API,Web API操作方法需要调用其他服务,而其他服务需要用户名和密码,那个么你们想以某种方式将它们从客户端传递到Web API吗?不。我想允许在浏览器中键入webapi url,webapi将从数据库返回数据。这是需要授权的单一服务。我正在寻找一种在url中输入用户名和密码的方法,并在WebAPI控制器中使用它们进行WebForms授权