惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
Stack Overflow Blog
Stack Overflow Blog
博客园 - 三生石上(FineUI控件)
T
Threat Research - Cisco Blogs
S
SegmentFault 最新的问题
V2EX - 技术
V2EX - 技术
Hacker News: Ask HN
Hacker News: Ask HN
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
P
Proofpoint News Feed
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
M
MIT News - Artificial intelligence
AI
AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
C
Cybersecurity and Infrastructure Security Agency CISA
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
U
Unit 42
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
H
Help Net Security
Recent Announcements
Recent Announcements
P
Privacy & Cybersecurity Law Blog
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 热门话题
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
H
Heimdal Security Blog
博客园 - 聂微东
S
Securelist
大猫的无限游戏
大猫的无限游戏
Cloudbric
Cloudbric
Cisco Talos Blog
Cisco Talos Blog

博客园 - yufan27209

博文阅读密码验证 - 博客园 JVM调优 【转】中文分词之HMM模型详解 xwiki enterprise 8.4.5使用https步骤 博文阅读密码验证 - 博客园 dubbo和shiro的整合,在服务端做权限验证 电商课题:分布式锁 Export large data from Gridview and Datareader to an Excel file using C# 博文阅读密码验证 - 博客园 sap学习笔记 设计模式读书笔记-----访问者模式DEMO修改 用户中心 - 博客园 MYSQL实现上一条下一条功能 SVN基本配置文件 单表60亿记录等大数据场景的MySQL优化和运维之道 MSSQL镜像—无见证服务器 风险控制-防刷 开发中两款工具 Remote Desktop Organizer 和zabbix EasyUI datagrid 编辑框焦点
.NET ActionFilterAttribute等
yufan27209 · 2017-05-05 · via 博客园 - yufan27209

public override void OnException(HttpActionExecutedContext actionExecutedContext)
{
//加LOG actionExecutedContext.Exception

//2.返回调用方具体的异常信息
if (actionExecutedContext.Exception is NotImplementedException)
{
actionExecutedContext.Response = new HttpResponseMessage(HttpStatusCode.NotImplemented);
}
else if (actionExecutedContext.Exception is TimeoutException)
{
actionExecutedContext.Response = new HttpResponseMessage(HttpStatusCode.RequestTimeout);
}
//.....这里可以根据项目需要返回到客户端特定的状态码。如果找不到相应的异常,统一返回服务端错误500
else
{
actionExecutedContext.Response = new HttpResponseMessage(HttpStatusCode.InternalServerError);
}

base.OnException(actionExecutedContext);
}

public class TokenAuthAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
{
base.OnActionExecuting(actionContext);

//POST的数据
using (Stream stream = actionContext.Request.Content.ReadAsStreamAsync().Result)
{
if (stream.Length > 0)
{
stream.Position = 0;
string data = string.Empty;
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
data = reader.ReadToEnd();
}
//加LOG
}
}

object token = null;
actionContext.ActionArguments.TryGetValue("token", out token);
//string token = string.Concat(HttpContext.Current.Request.Form["token"]);
ServiceK3Result result = new ServiceK3Result();
if (string.Concat(token).Equals("a"))
{
result.code = "401";
result.message = "IP受限制,请联系接口管理员!";
result.redirect = "";
actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized, JsonHelper.ObjectToJsonString(result));
}
}

public async override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
base.OnActionExecuted(actionExecutedContext);
//加结束LOG
}

}