I have a .NET MVC controller action that returns a JsonResult to a YUI AsyncRequest callback. All is working fine with the AsyncRequest call and the "Content" model data is successfully updated. How can I now assure that the user is logged before the AsyncRequest is made?
Normally I would use the [Authorize] attribute which returns an error back to my YUI AsyncRequest since it is expecting a Json result.
I've also tried checking "User.Identity.IsAuthenticated" wihtin the Action but still no love.. The RedirectToRoute seems to do nothing.
I have been able to send a Json result back to JS that indicated the user needs to login, but I'd rather have it redirect the user to the LogOn view.
Here is the Controller action:
[JsonFilter(Param="content"), JsonDataType=typeof(Content)]
public ActionResult SaveJson(Content content)
{
if (!User.Identity.IsAuthenticated)
RedirectToRoute(new { Action="LogOn", Controller="Account"});
contentRepository.Update(content);
return Json(new {Result = "sucess"});
}
TIA!