• RoadFlow2.7.5 MyController.cs


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace WebMvc
    {
        public class MyController : Controller
        {
            /// <summary>
            /// Action执行前判断
            /// </summary>
            /// <param name="filterContext"></param>
            protected override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                base.OnActionExecuting(filterContext);
                var myAttribute = filterContext.ActionDescriptor.GetCustomAttributes(typeof(MyAttributeAttribute), false);
                bool isCheckLogin = true;
                bool isCheckApp = true;
                bool isCheckUrl = true;
                if (myAttribute.Length == 1)
                {
                    MyAttributeAttribute myAttr = (MyAttributeAttribute)myAttribute[0];
                    isCheckLogin = myAttr.CheckLogin;
                    isCheckApp = myAttr.CheckApp;
                    isCheckUrl = myAttr.CheckUrl;
                }
                if (isCheckUrl)
                {
                    if (!Common.Tools.CheckReferrer(false))
                    {
                        filterContext.Result = Content("地址验证错误");
                        return;
                    }
                }
                if (isCheckLogin)
                {
                    string msg;
                    if (!this.CheckLogin(out msg))
                    {
                        if (filterContext.HttpContext.Request.IsAjaxRequest())
                        {
                            filterContext.Result = Content("{"loginstatus":-1, "url":""}");
                        }
                        else
                        {
                            string lastURL = System.Web.HttpContext.Current.Request.Url.PathAndQuery.UrlEncode();
                            filterContext.Result = Content(string.Concat("<script>",
                                msg.IsNullOrEmpty() ? "" : string.Format("alert('{0}');", msg),
                                string.Compare(filterContext.Controller.ToString(), "WebMvc.Controllers.HomeController", true) == 0 ? "top.location='" + Url.Content("~/Login") + "'" : "top.lastURL='" + lastURL + "';top.currentWindow=window;top.login();", "</script>"), "text/html");
                        }
                        return;
                    }
                }
                if (isCheckApp)
                {
                    string appMsg;
                    if (!Common.Tools.CheckApp(out appMsg))
                    {
                        filterContext.Result = Content("权限验证错误");
                        return;
                    }
                }
            }
            
            /// <summary>
            /// 验证登录
            /// </summary>
            /// <param name="msg"></param>
            /// <returns></returns>
            protected virtual bool CheckLogin(out string msg)
            {
                return WebMvc.Common.Tools.CheckLogin(out msg);
            }
    
            /// <summary>
            /// 当前登录用户ID
            /// </summary>
            public static Guid CurrentUserID
            {
                get
                {
                    return RoadFlow.Platform.Users.CurrentUserID;
                }
            }
    
            /// <summary>
            /// 当前用户
            /// </summary>
            public static RoadFlow.Data.Model.Users CurrentUser
            {
                get
                {
                    return RoadFlow.Platform.Users.CurrentUser;
                }
            }
    
            /// <summary>
            /// 当前用户姓名
            /// </summary>
            public static string CurrentUserName
            {
                get
                {
                    return RoadFlow.Platform.Users.CurrentUserName;
                }
            }
    
            /// <summary>
            /// 当前用户部门
            /// </summary>
            public static RoadFlow.Data.Model.Organize CurrentUserDept
            {
                get
                {
                    return RoadFlow.Platform.Users.CurrentDept;
                }
            }
    
            /// <summary>
            /// 当前用户部门ID
            /// </summary>
            public static Guid CurrentUserDeptID
            {
                get
                {
                    return RoadFlow.Platform.Users.CurrentDeptID;
                }
            }
    
            /// <summary>
            /// 当前用户部门名称
            /// </summary>
            public static string CurrentUserDeptName
            {
                get
                {
                    return RoadFlow.Platform.Users.CurrentDeptName;
                }
            }
    
            /// <summary>
            /// 当前用户单位
            /// </summary>
            public static RoadFlow.Data.Model.Organize CurrentUserUnit
            {
                get
                {
                    return RoadFlow.Platform.Users.CurrentUnit;
                }
            }
    
            /// <summary>
            /// 当前用户单位ID
            /// </summary>
            public static Guid CurrentUserUnitID
            {
                get
                {
                    return RoadFlow.Platform.Users.CurrentUnitID;
                }
            }
    
            /// <summary>
            /// 当前用户单位名称
            /// </summary>
            public static string CurrentUserUnitName
            {
                get
                {
                    return RoadFlow.Platform.Users.CurrentUnitName;
                }
            }
    
            /// <summary>
            /// 当前日期时间
            /// </summary>
            public static DateTime CurrentDateTime
            {
                get
                {
                    return RoadFlow.Utility.DateTimeNew.Now;
                }
            }
        }
    }
  • 相关阅读:
    完全二叉树求结点左右孩子编号
    while(p)的作用
    数组和链表的区别
    Seqlist L 与 Seqlist *L的区别
    exit和return
    java EE 的页面获得路径
    如何理解asp.net的AutoEventWireup
    asp.net的服务器控件客户端空件的区别以及如何刷新页面不靠数据库数据停留在页面
    外部样式?内联样式?内部样式表?区别
    html 与 htm的区别
  • 原文地址:https://www.cnblogs.com/Jeely/p/11262091.html
Copyright © 2020-2023  润新知