码迷,mamicode.com
首页 > 其他好文 > 详细

ActionFilterAttribute

时间:2015-06-05 19:13:52      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:

使用ActionFilterAttribute

做用户的验证

示例代码

 

public class SubScribeFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
string code = filterContext.HttpContext.Request.QueryString["code"];
object id = filterContext.RouteData.Values["id"];
if (id != null)
{
try
{
OAuthAccessTokenResult result = OAuthApi.GetAccessToken(WxConfig.AppId, WxConfig.AppSecret, code);
if (result != null)
{
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { Controller = "Weixin", action = "StudentInfo", openId = result.openid }));
}
else
{
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { Controller = "Weixin", action = "Error", id = "errorcode" }));
}
}
catch(Exception ex)
{

}

}
else
{
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { Controller = "Weixin", action = "Error", id = "nosubsribe" }));
}
base.OnActionExecuting(filterContext);
}
}

ActionFilterAttribute

标签:

原文地址:http://www.cnblogs.com/BlackCherry/p/4555313.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!