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

推荐订阅源

P
Proofpoint News Feed
博客园 - 聂微东
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
罗磊的独立博客
H
Help Net Security
L
LangChain Blog
T
Threat Research - Cisco Blogs
量子位
S
Securelist
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
The Hacker News
The Hacker News
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Blog of Author Tim Ferriss
T
Threatpost
Security Latest
Security Latest
P
Palo Alto Networks Blog
Microsoft Security Blog
Microsoft Security Blog
NISL@THU
NISL@THU
F
Full Disclosure
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Heimdal Security Blog
J
Java Code Geeks
Recorded Future
Recorded Future
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
B
Blog RSS Feed
月光博客
月光博客
C
Cisco Blogs
V
Visual Studio Blog
D
DataBreaches.Net
H
Hacker News: Front Page
博客园 - 叶小钗
N
News and Events Feed by Topic
爱范儿
爱范儿
A
Arctic Wolf

博客园 - 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
}

}