• 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;
                }
            }
        }
    }
  • 相关阅读:
    Spring Boot → 08:嵌入式Servlet容器自定义
    Spring Boot → 09:使用外置Servlet容器_tomcat9.0
    Spring Boot → 07:错误处理机制
    Spring Boot → 06:项目实战-账单管理系统
    Spring Boot → 05:Web开发
    zzz Objective-C的消息传递机制
    Objective-C中的SEL、IMP和Class类型(转)
    zzzObjective-C的动态特性
    zzz KVC/KVO原理详解及编程指南
    zzzzz iOS绘图教程
  • 原文地址:https://www.cnblogs.com/Jeely/p/11262091.html
Copyright © 2020-2023  润新知