zoukankan      html  css  js  c++  java
  • 在ASP.NET开始执行HTTP请求的处理程序之前

    using Dscf.Client.Web.Class;
    using Dscf.Client.Web.DscfService;
    using Dscf.Client.Web.Handler;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.ServiceModel;
    using System.Web;
    using System.Web.SessionState;
    namespace Dscf.Client.Web.HttpModules
    {
        public class Authentication : IHttpModule, IRequiresSessionState
        {
            public void Dispose() { }
            public void Init(HttpApplication context)
            {
                //在ASP.NET开始执行HTTP请求的处理程序之前引发这个事件
                context.PreRequestHandlerExecute += context_PreRequestHandlerExecute;
            }
            private void context_PreRequestHandlerExecute(object sender, EventArgs e)
            {
                HttpApplication application = (HttpApplication)sender;
                Uri uri = application.Context.Request.Url;
                string loginUrl = "/View/Login.aspx";
                if (!GetCommonUrl().Contains(uri.AbsolutePath.ToLower())    
                    && !uri.AbsolutePath.StartsWith("/combres.axd/")
                    && (uri.AbsolutePath.Contains(".aspx") || uri.AbsolutePath.Contains(".ashx")))
                {
                    OperaterInfo oper = application.Context.Session["Operator"] as OperaterInfo;
                    if (oper == null)
                    {
                        application.Response.Redirect(loginUrl, true);
                    }
                    List<PageRights> rights = application.Session["Rights"] as List<PageRights>;
                    if (rights == null || rights.Count <= 0)
                    {
                        if (oper.Roles == null || oper.Roles.Length <= 0)
                        {
                            GoToForbiddenPage(application.Context);
                        }
                        else
                        {
                            rights = new List<PageRights>();
                            foreach (var role in oper.Roles)
                            {
                                rights.AddRange(role.PageRights);
                            }
                            application.Session["Rights"] = rights;
                        }
                    }
                    int type;
                    int.TryParse(application.Request["type"], out type);
                    var right = rights.FirstOrDefault(m => m.PageUrl.Trim().ToLower() == uri.AbsolutePath.ToLower() && m.EditRight == type);
                    if (right == null)
                    {
                        if (uri.AbsolutePath.EndsWith(".ashx"))
                        {
                            application.Response.Write(new ResultMessage(false, "您没有权限进行此操作,请联系管理员获取更高权限!"));
                            application.Response.End();
                        }
                        else
                        {
                            GoToForbiddenPage(application.Context);
                        }
                    }
                }
            }
            private void GoToForbiddenPage(HttpContext context)
            {
                context.Response.Redirect("/Error/forbidden.html", true);
            }
            private List<string> GetCommonUrl()
            {
                List<string> list = new List<string>();
                list.Add("/View/Login.aspx".ToLower());
                list.Add("/View/FinaInvestList.aspx".ToLower());
                list.Add("/Handler/Login.ashx".ToLower());
                list.Add("/View/InvestLogin.aspx".ToLower());
                list.Add("/Handler/InvestLoginHandler.ashx".ToLower());
                list.Add("/Handler/FinaInvestHandler.ashx".ToLower());
                list.Add("/Handler/kefile_manager_json.ashx".ToLower());
                list.Add("/Handler/keupload_json.ashx".ToLower());
                list.Add("/Handler/CodeHandler.ashx".ToLower()); 
                list.Add("/Handler/IsUserInfoExistHandler.ashx".ToLower());
                list.Add("/Handler/JumpLoginHandler.ashx".ToLower());
                list.Add("/");
                return list;
            }
        }
    }
  • 相关阅读:
    vue2.0 移动端,下拉刷新,上拉加载更多 封装组件
    Mac 安装RN android开发环境
    JavaScript 复杂判断的更优雅写法
    JSBridge的原理及使用
    FlatList列表组件的使用
    React Native ScrollView中TextInput焦点问题
    pod update报错(Cocoapods: Failed to connect to GitHub to update the CocoaPods/Specs specs repo)报错解决方案
    如何在pc端通过adb连接手机调试,不用usb数据线
    react学习之搭建后台管理系统
    node+koa2+axios踩坑记
  • 原文地址:https://www.cnblogs.com/dullbaby/p/4991889.html
Copyright © 2011-2022 走看看