Angular“在控制器'Usuario'上找不到与请求匹配的操作。”

时间:2017-03-31 22:23:44

标签: javascript asp.net angularjs

我正在使用带有角度的asp.net web api,所以我正在制作恢复密码,我有以下步骤:

  1. 用户点击恢复密码
  2. 他输入了用户名并收到了带有恢复网址(带有特定令牌)的电子邮件,如:

    http://localhost:55720/Cliente/#/cambiarContrasena.html?Token=f0faa24e-a543-4806-820c-d0c31c69b180

  3. 我看到View没有问题但是当我尝试发布我收到的新凭据时

      

    “找不到与请求URI匹配的HTTP资源   'http://localhost:55718/api/usuario/cambiarContrasena'。”       “在控制器'Usuario'上找不到与请求匹配的动作。”

    角度控制器:

    (function (app) {
        'use strict';
    
        app.controller('cambiarContrasenaCtrl', cambiarContrasenaCtrl);
    
        cambiarContrasenaCtrl.$inject =['$scope', 'notificationService', '$rootScope', 'vcRecaptchaService', 'membershipService', '$state', 'apiService', '$window'];
    
        function cambiarContrasenaCtrl($scope, notificationService, $rootScope, vcRecaptchaService, membershipService, $state, apiService, $window) {
    
    
            $scope.usuario = {};
            $scope.cambiarContrasena = cambiarContrasena;
    
            function cambiarContrasena() {
                $('#recovery').prop('disabled', true);
                $('.page-spinner-bar').removeClass('hide');
                membershipService.cambiarContrasena($scope.usuario, credencialCorrecta, credencialIncorrecta);
            }
    
            function credencialCorrecta(response) {
                $('#recovery').prop('disabled', false);
                $('.page-spinner-bar').addClass('hide');
                notificationService.mostrarExito(response.data.mostrarExito);
                //redigir a estado, dashboard o previo en caso de existir
            }
    
            function credencialIncorrecta(response) {
    
                notificationService.mostrarError(response.data.errores);
                $('#recovery').prop('disabled', false);
                $('.page-spinner-bar').addClass('hide');
            }
    
    
        }
    
    })(angular.module('common.core'));
    

    传递后:membershipService.cambiarContrasena($scope.usuario, credencialCorrecta, credencialIncorrecta);会抛出错误消息

    app.js:

    .state('cambiarContrasena', {
                     url: "/cambiarContrasena.html",
                     templateUrl: "../SPA/cuenta/cambiarContrasena.html",
                     controller: "cambiarContrasenaCtrl",
                     authenticate: false,
                     data: { pageTitle: 'CAMBIAR CONTRASEÑA' },
                     resolve: {
                         deps: ['$ocLazyLoad', function ($ocLazyLoad) {
                             return $ocLazyLoad.load({
                                 name: 'portalTransporte',
                                 insertBefore: '#ng_load_plugins_before', // load the above css files before a LINK element with this ID. Dynamic CSS files must be loaded between core and theme css files
                                 files: [
                                     "/Metronic/pages/css/login-5.css",
                                     "/Metronic/custom/login.css"
                                 ]
                             });
                         }]
                     }
                 })
    

    membershipService.js

     function cambiarContrasena(usuario, completado, fallo) {
            apiService.post('/api/usuario/cambiarContrasena', usuario,
            completado,
            fallo);
        }
    

    控制器:

    namespace PortalDeTransporte.Web.Controllers
    {
        [RoutePrefix("api/usuario")]
        public class UsuarioController : ApiControllerBase
        {
      [AllowAnonymous]
            [HttpPost]
            [Route("cambiarContrasena")]
            public HttpResponseMessage cambiarContrasena(HttpRequestMessage request, string token)
            {
    
                return CreateHttpResponse(request, () =>
                {
                    HttpResponseMessage response = null;
    
                    if (ModelState.IsValid)
                    {
                        _usuarioRecuperacionService.CambiarContrasena(token);
                    }
                    return response;
                });
            }
        }
    }
    
    有人看错了吗?非常感谢帮助。此致

0 个答案:

没有答案