I have ASP.NET Core 2 MVC project. I am posting some data using JQuery to action.
Suppose User.Identity.Name is null and I want to redirect to AccountController
AccessDenied action.
I am unable to use RedirectToAction (also removed return). Because this goes back to JQuery success/error.
Is there any solution to this?
IN Controller
if (string.IsNullOrEmpty(User.Identity.Name))
return RedirectToAction(nameof(AccountController.AccessDenied), "Account");
In My JS
$.ajax({
type: "POST",
url: '/MyController/MyAction',
dataType: "json",
data: $(this).serialize(),
success: function (data, status, xhr) {
},
error: function (xhr, status, err) {
errorAlert(xhr.responseText, "ERROR");
}
});