• WebMethod Session


     [WebMethod(EnableSession = true)]
            public static string SayHello()
            { 
                 LxUserContext depno = HttpContext.Current.Session["UserContext"] as LxUserContext;
                 string depnos = depno.User.Department.ID; 
                  .......
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Net;
    using CityMgr;
    using CityMgr.Base;
    
    namespace WebApp
    {
        /// <summary>
        /// 用户上下文
        /// </summary>
        [Serializable]
        public class LxUserContext
        {
            /// <summary>
            /// 当前用户
            /// </summary>
            public LxPerson User { get; set; }
            /// <summary>
            /// 当前用户拥有的权限列表
            /// </summary>
            public List<LxAuth> HoldAuth { get; set; }
            /// <summary>
            /// 登录时间
            /// </summary>
            public DateTime LoginTime { get; set; }
            /// <summary>
            /// 客户端IP地址
            /// </summary>
            public string IP { get; set; }
    
            /// <summary>
            /// 验证权限
            /// </summary>
            /// <param name="authId">权限ID</param>
            /// <returns>是否拥有此权限</returns>
            public bool ValidateAuth(string authId)
            {
                return HoldAuth.Contains(new LxAuth() { ID = authId });
            }
    
            /// <summary>
            /// 验证权限
            /// </summary>
            /// <param name="authIds">权限ID列表</param>
            /// <returns>是否拥有此权限</returns>
            public bool ValidateAuth(string[] authIds)
            {
                bool result = false;
                foreach (var auth in authIds)
                {
                    if (HoldAuth.Contains(new LxAuth() { ID = auth }))
                        result = true;
                     break;
                }
                return result;
            }
    
            /// <summary>
            /// 获取当前用户登录上下文
            /// </summary>
            /// <returns>用户登录上下文</returns>
            [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.Read)]
            public static LxUserContext GetCurUserContext()
            {
                var obj = HttpContext.Current.Session["UserContext"] as LxUserContext;
                obj.User.Department.LoadData();
                return obj;
            }
           
        }
    }
  • 相关阅读:
    替换TStrings
    WordPress数据备份方案
    图像反色
    通过网络复制文件
    SQL Server的patindex和charindex的用法
    C冒泡排序 @100到200素数
    正则。IP验证
    C以二进制读、写、文本
    HTML下拉框、文本框、复选框!
    HTM页面获得本机时间
  • 原文地址:https://www.cnblogs.com/hellowzd/p/4658715.html
Copyright © 2020-2023  润新知