我正在使用$.post()Ajax调用servlet,然后使用生成的HTML片段替换div用户当前页面中的元素.但是,如果会话超时,服务器会发送重定向指令以将用户发送到登录页面.在这种情况下,jQuery正在用div登录页面的内容替换元素,迫使用户的目光确实见证了罕见的场景.
如何使用jQuery 1.2.6从Ajax调用管理重定向指令?
我正在尝试从操作方法重定向到外部URL但无法使其工作.有人可以解释我的错误吗?
public void ID(string id)
{
string url = string.Empty;
switch (id)
{
case "DB2FCB11-579F-4DA2-A68C-A6495B9BAAB5":
url = "http://www.somesite.com";
break;
}
Response.Redirect(url, true);
}
Run Code Online (Sandbox Code Playgroud)
谢谢,克里斯
我需要从OnActionExecuting方法重定向到外部网址(例如“ www.google.com”)。现在我正在使用这样的东西:
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (!HttpContext.Current.User.Identity.IsAuthenticated)
{
var redirectUrl = "www.google.com";
try
{
var isAjaxRequest = filterContext.HttpContext.Request.IsAjaxRequest();
if (isAjaxRequest)
{
filterContext.HttpContext.Response.StatusCode = SessionController.CustomHttpRedirect;
filterContext.HttpContext.Response.StatusDescription = redirectUrl;
filterContext.Result = new JsonResult
{
Data = new { Redirect = redirectUrl },
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
}
else
{
filterContext.Result = new RedirectResult(redirectUrl, true);
}
return;
}
else
{
throw new LoggedOutException();
}
}
catch
{
throw new LoggedOutException();
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题在于它没有将我重定向到“ www.google.com”,而是将其重定向到“ http:// localhost:1234 / www.google.com ”(我在本地尝试)。有什么办法解决这个问题?谢谢