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();
                }
            }
        }

  • 相关阅读:
    _proto_和prototype的区别
    ajax
    图片预加载
    loading动画
    WinSCP
    检测竖屏 横屏
    webstrom hbuilder快捷键
    vue 引入sass
    npm install -save 和 -save-dev 区别
    打乱数组顺序
  • 原文地址:https://www.cnblogs.com/huaqiqi/p/4383424.html
Copyright © 2011-2022 走看看