• 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

  • 相关阅读:
    Jquery开发技巧汇总
    (转)
    C#中的委托和时间
    asp.net中like 使用参数化(转)
    省市选择
    安卓对话框
    z转自 西西吹雪
    winform控件验证技术(转)
    C#获取网卡Mac地址 .(转)
    关于GDI+错误的修正
  • 原文地址:https://www.cnblogs.com/jianghaidong/p/4744495.html
Copyright © 2020-2023  润新知