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;
            }
        }
    }
  • 相关阅读:
    HAOI2018 简要题解
    HAOI2017 简要题解
    BZOJ 5477: 星际穿越
    HAOI2016 简要题解
    C#oracle还原imp实例
    oracle备份imp命令大全
    C#oracle备份和还原
    win10安装CAD后出现致命错误
    Oracle 恢复数据后,数据库中中文变成问号解决方法
    CAD 安装时出现.net frameword 3.5安装不上的问题
  • 原文地址:https://www.cnblogs.com/dullbaby/p/4991889.html
Copyright © 2011-2022 走看看