Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 帐户/登录HTTP post的映射路由_C#_Asp.net_Asp.net Mvc_Angularjs_Asp.net Mvc 4 - Fatal编程技术网

C# 帐户/登录HTTP post的映射路由

C# 帐户/登录HTTP post的映射路由,c#,asp.net,asp.net-mvc,angularjs,asp.net-mvc-4,C#,Asp.net,Asp.net Mvc,Angularjs,Asp.net Mvc 4,我一直在使用上面链接中的教程构建一个ASP.NET+AngularJS应用程序 $scope.login = function () { console.log("DERP"); var result = LoginFactory($scope.loginForm.emailAddress, $scope.loginForm.password, $scope.loginForm.rememberMe); result.then(function (result) {

我一直在使用上面链接中的教程构建一个ASP.NET+AngularJS应用程序

$scope.login = function () {
    console.log("DERP");
    var result = LoginFactory($scope.loginForm.emailAddress, $scope.loginForm.password, $scope.loginForm.rememberMe);
    result.then(function (result) {
        if (result.success) {
            if ($scope.loginForm.returnUrl !== undefined) {
                console.log("im in");
                $location.path('/home');
            } else {
                console.log("login failed");
                $location.path($scope.loginForm.returnUrl);
            }
        } else {
            $scope.loginForm.loginFailure = true;
        }
    });
}
执行此函数时,HTTP POST请求运行一段时间,然后返回一个内部服务器错误。它不会返回成功或失败

POST http://localhost:54865/Account/Login 500 (Internal Server Error)
  (anonymous function) @ angular.js:8495
  t @ angular.js:8291
  g @ angular.js:8025
  J @ angular.js:11498
  J @ angular.js:11498
  (anonymous function) @ angular.js:11584
  k.$eval @ angular.js:12608
  k.$digest @ angular.js:12420
  k.$apply @ angular.js:12712
  (anonymous function) @ angular.js:18980
  (anonymous function) @ angular.js:2823
  q @ angular.js:325c @ angular.js:2822
我对ASP.NET MVC相当陌生,所以我对这些概念没有很好的掌握。但我怀疑问题出在我的
RouteConfig.cs
文件中,教程已经指示我明确说明每个AngularJS视图的所有不同路径。我唯一的
/Account/Login
路线如下:

routes.MapRoute(
    name: "login",
    url: "Account/Login",
    defaults: new { controller = "Account", action = "Login" });
如果我要创建一个MVC路由来接受对帐户/登录的HTTP POST请求,我将如何实现它?我完全偏离轨道了吗

编辑

以下是我的
AccountController.cs
文件的相关部分:

[AllowAnonymous]
public ActionResult Login()
{
    return View();
}
[HttpPost]
[AllowAnonymous]
public async Task<bool> Login(MyApp.Entities.ViewModels.LoginViewModel model)
{
    var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false);
    switch (result)
    {
       case SignInStatus.Success:
            return true;
       default:
            ModelState.AddModelError("", "Invalid login attempt.");
            return false;
    }
}
[AllowAnonymous]
公共操作结果登录()
{
返回视图();
}
[HttpPost]
[异名]
公共异步任务登录(MyApp.Entities.ViewModels.LoginViewModel模型)
{
var result=wait SignInManager.PasswordSignInAsync(model.Email、model.Password、model.RememberMe、false);
开关(结果)
{
案例标志状态成功:
返回true;
违约:
AddModelError(“,”登录尝试无效“);
返回false;
}
}

您的请求似乎击中了MVC控制器。您可以尝试在服务器代码上设置断点,并查看错误是什么。对于Angular,您没有在
然后
中添加错误回调(第二个)参数以接收http错误。同时分享你的控制器方法你不需要一个控制器和一个动作的
Account/Login
路由映射,你原来的
{controller}/{action}/{id}
将为你充分处理这个问题。@Coulton按照第2部分教程的说明,我手动映射了这些路由以避免404服务器错误。@Chandermani我已将这两个控制器方法添加到我的问题中。您的请求似乎击中了MVC控制器。您可以尝试在服务器代码上设置断点,并查看错误是什么。对于Angular,您没有在
然后
中添加错误回调(第二个)参数以接收http错误。同时分享你的控制器方法你不需要一个控制器和一个动作的
Account/Login
路由映射,你原来的
{controller}/{action}/{id}
将为你充分处理这个问题。@Coulton按照第2部分教程的说明,我手动映射这些路由以避免404服务器错误。@Chandermani我已将这两个控制器方法添加到我的问题中。