zoukankan      html  css  js  c++  java
  • mvc通过反射获取action方法(适用于权限控制)

    public static List<string> GetALLPageByReflection()
    {
    List<string> actions = new List<string>();
    var asm = System.Reflection.Assembly.GetExecutingAssembly();
    System.Collections.Generic.List<Type> typeList = new List<Type>();
    var types = asm.GetTypes();
    foreach (Type type in types)
    {
    string s = type.FullName.ToLower();
    if (type.Name.StartsWith("AccountCont")) continue;
    if (s.StartsWith("开始字符串") && s.EndsWith("结束字符串"))
    typeList.Add(type);
    }
    typeList.Sort(delegate(Type type1, Type type2) { return type1.FullName.CompareTo(type2.FullName); });
    foreach (Type type in typeList)
    {
    //Response.Write(type.Name.Replace("Controller","") + "<br/> ");
    System.Reflection.MemberInfo[] members = type.FindMembers(System.Reflection.MemberTypes.Method,
    System.Reflection.BindingFlags.Public |
    System.Reflection.BindingFlags.Static |
    System.Reflection.BindingFlags.NonPublic | //【位屏蔽】
    System.Reflection.BindingFlags.Instance |
    System.Reflection.BindingFlags.DeclaredOnly,
    Type.FilterName, "*");
    foreach (var m in members)
    {
    if (m.DeclaringType.Attributes.HasFlag(System.Reflection.TypeAttributes.Public) != true)
    continue;
    string controller = type.Name.Replace("Controller", "");
    string action = m.Name;
    string url = "/" + controller + "/" + action;
    if (!action.Contains("<"))
    {
    actions.Add(url);
    }
    }
    }
    return actions;
    }

    来自小聪ssc

  • 相关阅读:
    HDU1285-确定比赛名次(拓扑排序)
    ftp sftp
    Python with 用法
    odoo 非root用户运行不成功
    linux 删除软连接
    vscode wsl php
    WSL 修改默认登录用户为root
    WSL ssh服务自启动
    odoo 获取model的所有字段
    odoo 在"动作"("Action")菜单中添加子菜单, 点击子菜单弹窗自定义form
  • 原文地址:https://www.cnblogs.com/jianghaidong/p/4744495.html
Copyright © 2011-2022 走看看