httpでgetが返される理由は、すべてのページのhtmlを返しますが、returnUrl
( 'Home/Index')の値は返しません。角度js http getすべてのページ
問題はawait SignInAsync(user, model.RememberMe);
にあると思います。
コントローラー:
[HttpGet]
[AllowAnonymous]
public async Task<JsonResult> Login(string UserName, string Password, bool RememberMe, string returnUrl)
{
LoginViewModel model = new LoginViewModel();
model.Password = Password;
model.UserName = UserName;
model.RememberMe = RememberMe;
if (ModelState.IsValid)
{
var user = await UserManager.FindAsync(model.UserName, model.Password); if (user != null)
{
if (user.ConfirmedEmail == true)
{
await SignInAsync(user, model.RememberMe);
return Json(returnUrl, JsonRequestBehavior.AllowGet);
}
else
{
ModelState.AddModelError("", "Confirm Email Address.");
}
}
else
{
ModelState.AddModelError("", "Invalid username or password.");
}
}
// If we got this far, something failed, redisplay form
return Json(returnUrl, JsonRequestBehavior.AllowGet);
}
AngularJS:
$scope.answer = function (answer) {
$scope.returnUrl = '/Home/Index';
$http({
method: 'GET',
url: '/Account/Login',
params: {
UserName: $scope.model.UserName,
Password: $scope.model.Password,
RememberMe: $scope.model.RememberMe,
returnUrl: $scope.returnUrl
}
}).then(function (response) {
console.log(response.data);
}, function() {
console.log("Error occured");
});
HTML応答ログイン成功は、それがにreturnurlとJSONが返されます場合は、あなたのコード、 に基づいて
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>About - My ASP.NET Application</title>
<link href="/Content/site.css" rel="stylesheet"/>
<script src="/Scripts/modernizr-2.6.2.js"></script>
<script src="/Scripts/angular.js"></script>
<script src="/Scripts/Custom/Login.js"></script>
<script src="/Scripts/angular-material/angular-material.js"></script>
<script src="/Scripts/angular-animate/angular-animate.js"></script>
<script src="/Scripts/angular-aria/angular-aria.js"></script>
<script src="/Scripts/angular-messages.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-114/svg-assets-cache.js"></script>
<link href="https://cdn.gitcdn.link/cdn/angular/bower-material/v1.0.8/angular-material.css" rel="stylesheet" />
<link href="https://material.angularjs.org/1.0.8/docs.css" rel="stylesheet" />
<link href="/Content/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Application name</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
<li><a href="/Home/About">About</a></li>
<li><a href="/Home/Contact">Contact</a></li>
<li><div ng-app="LoginApp" ng-controller="LoginCtrl"><input type="button" value="Login" ng-click="showAdvanced($event)" /></div></li>
</ul>
<form action="/Account/LogOff" class="navbar-right" id="logoutForm" method="post"><input name="__RequestVerificationToken" type="hidden" value="78GcsaZMHozpxPWZojKt_U4oOlCC91bdiNLnrM9bnGkHAwTdludG--qpyQSGXaurmBHnyYUiIlGpNsGfkskwnMHyc_BozsM2pdl4IWBoWos27DcNf3c57PLPRcmNBm-INZRgLICtO1PG4DcOWJRm6yj6Sr_kSDElCuPf-H8AD2BACTChafGXEic38UObx3PdnTDg-C6Iah7AyhjZvagKlw2" /> <ul class="nav navbar-nav navbar-right">
<li>
<a href="/Account/Manage" title="Manage">Hello Anton!</a>
</li>
<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
</ul>
</form>
</div>
</div>
</div>
<div class="container body-content">
<h2>About</h2>
<hr />
<footer>
<p>© 2016 - My ASP.NET Application</p>
</footer>
</div>
<script src="/Scripts/jquery-1.9.1.js"></script>
<script src="/bundles/bootstrap"></script>
</body>
</html>
'/ Home/Index'は完全なページを返すアクションではありませんか? –
@HuguesStefanski、しかし、私はそれが文字列 '/ Home/Index'だけを返すべきだと思った。 – A191919