MVC Ajax调用Action时-OnActionExecuting RedirectResult 无法跳转的处理办法
public class BaseController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (Session["userInfo"] == null)
{
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
filterContext.Result = new HttpStatusCodeResult();
filterContext.HttpContext.Response.Write("/Desktop/Login/Index");
return;
}
else
{
filterContext.Result = new RedirectResult("/Desktop/Login/Index");
return;
}
}
base.OnActionExecuting(filterContext);
}
}
}
(function ($) {
//有可能导致jquery里面的done方法未定义;所以有时候可以全部注释掉;
var _ajax = $.ajax;
$.ajax = function (opt) {
var fn = {
error: function (XMLHttpRequest, textStatus, errorThrown) { },
}
if (opt.error)
fn.error = opt.error;
var _opt = $.extend(opt, {
error: function (XMLHttpRequest, textStatus, errorThrown) {
if (XMLHttpRequest.status == "499")
window.location.href = "/Desktop/Login/Index";
else
fn.error(XMLHttpRequest, textStatus, errorThrown);
}
});
_ajax(_opt);
};
})(jQuery);
$.ajaxSetup({
statusCode: {
499: function (data) {
window.location.href = data.responseText;
}
}
});
$.ajax({
type: "POST",
url: "/desktop/language/index",
data: { language: getCookie("languageCode") },
datatype: "json",
success: function (returndata) {
//alert("second success");
}
});
//如果是Ajax.BeginForm,跳转到登陆页方式为如下:
@using (Ajax.BeginForm("GetSystemStatusTracking", "ReportQuery",
new AjaxOptions() { UpdateTargetId = "TRACKING_NEWLIST",
OnBegin = "showModal",
OnComplete = "hideModal",
OnFailure = "failureProcess"
}))
{
}
function failureProcess(data) {
if (data.status == 499)
window.location.href = (data.responseText == '') ? window.location.href = "/Desktop/Login/Index" : data.responseText;
}
特别注意:当用IIS发布时,客户端访问会报错“ 自定义错误模块不能识别此错误”,但调试时和本机发布本机访问都不会报错;
初步怀疑是服务器和客户端字体解析问题导致。代码需改为如下:
$.ajaxSetup({
statusCode: {
499: function (data) {
window.location.href = "/Desktop/Login/Index";
}
}
});
function failureProcess(data) {
if (data.status == 499) {
window.location.href = "/Desktop/Login/Index";
}
}
MVC Ajax调用Action时-OnActionExecuting RedirectResult 无法跳转的处理办法的更多相关文章
- 爱上MVC~ajax调用分部视图session超时页面跳转问题
回到目录 这个问题出现了很多年了,都没有解决,问题是这样的,有一个需要授权才可以访问的分部视图,在一个view中使用ajax的方法去调用它,然后更新页面的局部DIV,这时,如果你长时间不操作,sess ...
- mvc ajax访问后台时session过期无法跳转到Login页面问题解决
public class BaseController : Controller { protected User UserInfo { set { Session["UserInfo&qu ...
- asp.net mvc 使用Ajax调用Action 返回数据【转】
使用asp.net mvc 调用Action方法很简单. 一.无参数方法. 1.首先,引入jquery-1.5.1.min.js 脚本,根据版本不同大家自行选择. <script src=& ...
- Asp.Net MVC ajax调用 .net 类库问题
如果你还在为 ajax 调用 .net 类库还束手无策的话,相信这篇博客将帮助你解决这个世纪问题! 因为Visual Studio 内置了asp.net mvc ,不过当你添加asp.net mvc项 ...
- Struct2_使用Ajax调用Action方法并返回值
一.Login.jsp 1.<head>引入jquery: <script type="text/javascript" src="http://aja ...
- Spark为什么只有在调用action时才会触发任务执行呢(附算子优化和使用示例)?
Spark算子主要划分为两类:transformation和action,并且只有action算子触发的时候才会真正执行任务.还记得之前的文章<Spark RDD详解>中提到,Spark ...
- 使用jQuery的ajax调用action的例子
直接使用ajax请求会比较繁琐,但是jQuery为我们提供了简单使用ajax的方法. 下面是一个在jQuery easyUI中,利用ajax请求,使下拉菜单关联文本框的例子.其中ajax请求就是8-1 ...
- 通过Web API调用Action时各种类型输入参数传递值的方法
本人微信公众号:微软动态CRM专家罗勇 ,回复280或者20180906可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me . Dy ...
- SSH框架下ajax调用action并生成JSON再传递到客户端【以get和post方式提交】
需要完成的任务: 主要是把JSP页面上图片ID传给服务器端,服务器读取cookie看是否有username,如果有则根据ID读取MongoDB数据库,读出图片URL,再存放到mysql中的collec ...
随机推荐
- hdu 3342 Legal or Not (拓扑排序)
重边这样的东西 仅仅能呵呵 就是裸裸的拓扑排序 假设恩可以排出来就YES . else NO 仅仅须要所有搜一遍就好了 #include <cstdio> #include < ...
- Cocos2d-html5入门之2048游戏
一.介绍 Cocos2d-JS是Cocos2d-x的Javascript版本,它的前身是Cocos2d-html5.在3.0版本以前叫做Cocos2d-html5,从3.0版本开始叫做Cocos2d- ...
- Consider using EXISTS instead of IN
redgate给出的提示 https://documentation.red-gate.com/codeanalysis/performance-rules/pe019 In theory, EXIS ...
- Java 数组的 12 个方法
1. 声明一个数组 String[] aArray = new String[5]; String[] bArray = {"a","b","c&q ...
- eclipse中Kotlin的基础应用
最近逛网站时无意中发现有一门新语言谈论很广-- kotlin ,能够完全兼容Java.这就引起了楼主的好奇心,据所周知,Java就是因为多平台的支持 才流行起来.OK,闲话不多说,下面看图讲代码. 1 ...
- vue实现全选,反选
1.example.vue <template> <table class="table-common"> <tr> <th class= ...
- codevs3327选择数字(单调队列优化)
3327 选择数字 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 给定一行n个非负整数a[1]..a[n].现 ...
- redis过期策略和内存淘汰机制
目录 常见的删除策略 redis使用的过期策略:定期删除+惰性删除 定期删除 惰性删除 为什么要采用定期删除+惰性删除2种策略呢? redis内存淘汰机制 常见的删除策略 1.定时删除:在设置键的过期 ...
- 在3D中两条射线的相交性检测
摘自[3D数学基础: 图形与游戏开发] 考虑在3D中两条以参数形式定义的射线: \(\vec{r_1}(t_1)=\vec{p_1}+t_1\vec{d_1}\) \(\vec{r_2}(t_2)=\ ...
- ACM_题目这么难,来局愉快的昆特牌吧
题目这么难,来局愉快的昆特牌吧 Time Limit: 2000/1000ms (Java/Others) Problem Description: 小Z打比赛,然而比赛太难了,他坐在电脑面前被题淹没 ...