1 Star 0 Fork 0

codebug/DigitalShopAssistant

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
BaseController.cs 1.52 KB
一键复制 编辑 原始数据 按行查看 历史
codebug 提交于 2016-04-10 18:25 +08:00 . 木之春项目迁移
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using DSAServer.Models;
using DSAServer.Utils;
using UrlHelper = DSAServer.Utils.UrlHelper;
namespace DSAServer.Controllers
{
public class BaseController : Controller
{
protected T getRequestData<T>(bool autoCheck = true)
{
string para = this.Request["data"];
T data = JsonHelper.DeserializeObject<T>(CharSetHelper.UrlDeCode(para, Encoding.UTF8));
if (data == null)
{
LogUtil.Info("error:" + para);
throw new ArgumentException("error data!");
}
else
{
//LogUtil.Info("para:" + para);
}
return data;
}
protected override void OnException(ExceptionContext filterContext)
{
if (filterContext.Exception is ArgumentException)
{
filterContext.Result = new JsonResult() { Data = new InvokeResult() { msg = filterContext.Exception.Message }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
else
{
filterContext.Result = new JsonResult() { Data = new InvokeResult() { msg = filterContext.Exception.Message }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };//"An error occurred while executing"
}
filterContext.ExceptionHandled = true;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/codebug/DigitalShopAssistant.git
git@gitee.com:codebug/DigitalShopAssistant.git
codebug
DigitalShopAssistant
DigitalShopAssistant
master

搜索帮助