I use asp.net mvc 5 application logging with the following logical action in AccountController:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
## not working, just a trial
##returnUrl = "Dashboard#!/requests";
if (!ModelState.IsValid)
{
return View(model);
}
var result = await > >SignInManager.PasswordSignInAsync(model.UserName, model.Password,
model.RememberMe, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
}
}
and with this form:
<section id="loginForm">
@using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Use a local account to log in.</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.UserName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.PasswordFor(m => m.Password, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<div class="checkbox">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Log in" class="btn btn-default" />
</div>
</div>
@*<p>
@Html.ActionLink("Register as a new user", "Register")
</p>*@
@* Enable this once you have account confirmation enabled for password reset functionality
<p>
@Html.ActionLink("Forgot your password?", "ForgotPassword")
</p>*@
}
</section>
After logging in, I want the user to redirect the URL "Dashboard #! / Requests" where Dashboard is an ASP.NET MVC 5 Controller and / requests an Angular route using HTML5 and! Prefix:
$locationProvider.html5Mode(false).hashPrefix('!'); // This is for Hashbang Mode
app.config (function ($ routeProvider, $ locationProvider) {$ RouteProvider
.when('/requests', {
templateUrl: '/Template/Request/Index.html',
controller: 'requestsController'
})
.when('/request/:wf/:requestId', {
templateUrl: function(params) {
return '/Template/Request/' + params.wf + '/Open.html';
},
controller: 'requestsController'
});
$locationProvider.html5Mode(false).hashPrefix('!');
});
How to redirect user to url in combination with asp.net mvc 5 and angular controller?