分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

asp.net ?重写OnException返回json或跳转新页面

发布时间:2023-09-06 01:13责任编辑:赖小花关键词:jsjson
 ???????protected override void OnException(ExceptionContext filterContext) ???????{ ???????????// 此处进行异常记录,可以记录到数据库或文本,也可以使用其他日志记录组件。 ???????????// 通过filterContext.Exception来获取这个异常。 ???????????filterContext.ExceptionHandled = true;//组织web.config配置customerror处理 ???????????string requestType = filterContext.HttpContext.Request.RequestType.ToString();//获取请求类型 ???????????UrlHelper url = new UrlHelper(filterContext.RequestContext); ???????????//判断是否为get请求,如果为get请求,跳转指定页面,如果不是返回json ???????????if (requestType.ToUpper() == "GET") ???????????{ ???????????????filterContext.Result = new RedirectResult(url.Action("error", "Error"));//跳转到新页面 ???????????} ???????????else ???????????{ ???????????????filterContext.Result = new JsonResult() { Data = new { errorcode = 2, message = filterContext.Exception.Message }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };//返回json数据 ???????????} ???????????// 执行基类中的OnException ???????????//base.OnException(filterContext); ???????}

asp.net ?重写OnException返回json或跳转新页面

原文地址:http://www.cnblogs.com/Chavezcn/p/7580624.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved