user3101689
user3101689

Reputation: 41

Redirect to different area based on role in forms authentication on ajax success

I am working on MVC with EF, Can Some one help with the below scenario. I am using Forms Authentication in MVC 5. I made a jquery ajax call to controller to login the user by sending username and pwd, Upon success I am setting the forms authentication cookie, and checking the role of the user. Here I am struck. I am using RedirectToAction method to navigate to different areas based on the role. But Its not navigating. My Return statement is

if (roleProvider.IsUserInRole(userName, "Buyer"))
{
return RedirectToAction("Index", "BHome", new { area = "Buyer" });
}

Thanks for the Help

Upvotes: 0

Views: 156

Answers (1)

Matt Bodily
Matt Bodily

Reputation: 6423

you can't redirect a user from an ajax call. The ajax call is async so it will stay on the same page. to redirect then you will need to add a window.location to the success of your ajax call

success: function(result){
    if(result.Success){
        window.location = '@Url.Action("newAction", "newController")';
    }
}

Upvotes: 2

Related Questions