zoukankan      html  css  js  c++  java
  • 特性Attribute 的使用

      [IdentityAuthorize]   
            public ActionResult Index()
            {
                return View("~/Views/Index.cshtml");
            }

      [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
        public class IdentityAuthorizeAttribute : ActionFilterAttribute, IActionFilter
        {
            /// <summary>
            /// 验证是否登陆,没有登陆跳转到 登陆页
            /// </summary>
            /// <param name="filterContext">上下文</param>
            public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                try
                {
                    if (!Identity.IsAuthenticated)
                    {
                        string url = HttpContext.Current.Request.Url.ToString();
                        HttpContext.Current.Response.Clear();
                        HttpContext.Current.Response.Write("<script>window.top.location='" + Config.WapLoginUrl + "?backurl=" + url + "'</script>");
                        HttpContext.Current.Response.End();
                    }
                    base.OnActionExecuting(filterContext);
                }
                catch (Exception exception)
                {
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.Write(exception.Message);
                    HttpContext.Current.Response.End();
                }
            }
        }

  • 相关阅读:
    如何学好编程
    进制转换
    第五周学习总结 20201204 于瀛鹏
    xor运算
    20201204 于瀛鹏 第四周学习总结
    20201204 于瀛鹏 第三周学习总结
    IEEE754浮点数
    base64编码
    罗马数字(1-3999)转阿拉伯数字
    俄罗斯方块
  • 原文地址:https://www.cnblogs.com/huaqiqi/p/4383424.html
Copyright © 2011-2022 走看看