Pregunta

So I'm trying to make a call to this specific method:

[HttpGet]
public int GetLogin(string u, string p)
{
    UserLogin uL = new UserLogin();
    return (int)uL.Authenticate(u, p);
}

However it keeps calling this method in my Controller instead:

public IEnumerable<string> Get()
{
    return new string[] { "value1", "value2" };
}

^^ Which is the generated code in the Controller.

Here Angular code for my factory and, more importantly, my URI:

var loginFactory = angular.module('loginService', ['ngResource'])

loginFactory.factory('UserLogin', function ($resource) {
    return $resource('api/login?:username?:password', {}, {
        query: {
            method: 'GET',
            params: { username: 'hunter', password: 'hunter' },
            isArray:true
        }
    });
});

Any insight would be much appreciated. Thanks.

¿Fue útil?

Solución

Change your resource to this:

$resource('api/GetLogin?u=:username&p=:password', {}, {  // if that's the right route
    query: {
        method: 'GET',
        params: { username: 'hunter', password: 'hunter' },
        isArray:true
    }
});

Otros consejos

Is your request going like api/login?username=something&password=something...? if yes, the parameter names on the action should match the query string parameter names:

public int GetLogin(string **username**, string **password**)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top