I am new to angularjs and working on asp.net MVC with angularjs. I am using angularjs states to redirect another page. When I redirect to login page from OnAuthorization of MVC login page renders in the current page rather than separate page
public override void OnAuthorization(AuthorizationContext filterContext)
{
if(filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true)
|| filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true))
return;
CurrentUserToken = sessionManager.CurrentUserToken;
if (string.IsNullOrEmpty(CurrentUserToken))
HandleUnauthorizedRequest(filterContext);
}
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
//string destinationUrl = UrlHelper.GenerateContentUrl("http://localhost:49363/Account/SignIn", filterContext.HttpContext);
//JavaScriptResult result = new JavaScriptResult()
//{
// Script = "window.location='" + destinationUrl + "';"
//};
//result.ExecuteResult(filterContext);
//filterContext.HttpContext.Response.StatusCode = 403; //There is no HTTP status code for session timeout. We are using this code as it stands for "Forbidden" which is closer.
//filterContext.Result = new JsonResult
//{
// JsonRequestBehavior = JsonRequestBehavior.AllowGet,
// Data = new { error = true, httpCode = 403, status = "Error", message = "Session expired. Please relogin." }
//};
var url = new UrlHelper(filterContext.RequestContext);
var verifyEmailUrl = url.Action("SignIn", "Account", null);
filterContext.Result = new RedirectResult(verifyEmailUrl);
// filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { Action = "SignIn", Controller = "Account" }));
}
else
{
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { Action = "SignIn", Controller = "Account" }));
}
}
Please give me some suggestions to get out of this issue.