0

My javascript method-

visitorApp.controller('LoginController', function ($scope,$http) {
    $scope.submit = function (isValid) {
        if (isValid) {
            var loginModel = {
                UserName: $scope.UserName,
                PassWord: $scope.Password
            };           

        $http.post(
            '/api/VisitorWeb/VerfiyLogin',
            JSON.stringify(loginModel),
            {
                headers: {
                    'Content-Type': 'application/json'
                }
            }
        ).success(function (data) {
            alert("Hi" +data);
            $scope.message = data;
        });


    }
}

});

My web api method -

[HttpPost]
        public UserLoginDomainModel VerifyLogin(UserLoginDomainModel loginModel)
        {
            //do some business logic
            return loginModel;
        }

My webapiconfig file

public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));

            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}"
            );
        }
    }

I am getting 404 response from server.

"NetworkError: 404 Not Found - http://localhost:43516/api/VisitorWeb/VerfiyLogin"

I was try to follow this link POSTing from Angular to .net WebAPI but some how it is not working for me.

6
  • Is it cross origin ? Commented May 18, 2016 at 11:48
  • a stupid question but your front end and backend are running on the same instance and port ?shouldn't it be like this $http.post(apiHost+ '/api/VisitorWeb/VerfiyLogin' .. Commented May 18, 2016 at 11:51
  • @YinGang- it is not cross origin. Everything is in the same web project Commented May 18, 2016 at 11:51
  • @MayK- it is running on same port. Commented May 18, 2016 at 11:52
  • @MayK- is it compulsory to provide the localhost port in uri, without it will never work? Commented May 18, 2016 at 11:53

1 Answer 1

2

I think you have a typo here:

 $http.post(
            '/api/VisitorWeb/VerfiyLogin',
            JSON.stringify(loginModel),
            {
                headers: {
                    'Content-Type': 'application/json'
                }
            }

Your service method is named VerifyLogin and not VerfiyLogin from what I can see.

Sign up to request clarification or add additional context in comments.

1 Comment

you got me , it was the typo which was the problem, now it is working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.