I'm new to AngularJS and I'm starting to create a sample application, this application has 2 views:
public JsonResult Login(string credentials)
bool returnVal = false;
FormsAuthentication.SetAuthCookie("DUMMY USER", true);
success = returnVal
public JsonResult GetPersons()
success = false
<forms loginUrl="/login" name=".ASPXFORMSAUTH" protection="All" timeout="1" slidingExpiration="true" />-->
GET http://localhost:21871/login?ReturnUrl=%2fperson%2fGetPersons 404 (Not Found)
You can use any authentication/authorization mechanism that you like. But when you are calling
$http.post() you expect to receive a JSON object. But if you are not authenticated you will be redirected to login page which is an HTML page. Hence your code which is checking for success will fail.
You need to create a new custom authorize filter (like MyAuthorize) that authenticate/authorizes your user by any available technology (SimpleMembership, OAuth, etc) and if authentication fails then instead of returning a
RedirectResult, returns a JSON object with an Error flag. Then you can check that flag after each
$http.post(), and redirect the user from client side. We always develop our own communication service that calls
$http.post and always make that check over there.