Baris Halici

Baris Halici

  • NA
  • 23
  • 615

Areas-Controller-Action Listing for URL Authorize

Jun 6 2018 10:11 AM
  1. var areas = Assembly.GetExecutingAssembly().GetTypes().Where(type => typeof(AreaRegistration).IsAssignableFrom(type)).ToList();  
  2.     foreach(var area in areas)  
  3.     {  
  4.         var controllers = Assembly.GetExecutingAssembly().GetTypes().Where(type => typeof(Controller).IsAssignableFrom(type)).ToList();  
  5.         foreach (var controller in controllers)  
  6.         {  
  7.              var methods = controller.GetMethods(BindingFlags.Public | BindingFlags.Instance);  
  8.              foreach (var method in methods)  
  9.              {  
  10.                   if (method.ReturnType == typeof(ActionResult))  
  11.                   {  
  12.                         lstControllerActions.Add(string.Format("Area -> Controller -> Action : {0} -> {1} -> {2}", area.Name, controller.Name, method.Name));  
  13.                   }  
  14.              }  
  15.          }  
  16.     }  
it can be a different method.  As a result, i want to get all the urls from the application.
 
I planning authorization in the my application. And, I need these (area name, controller name, action name) to ask when a request is made. In short, the URL address. I tried these.
 
Example:
  • (AreaRegistration)
    • Trial1Controller
      • Home ActionResult >>> /Trial/Trial1/Home/
      • A ActionResult >>> /Trial/Trial1/A/
      • B ActionResult >>> /Trial/Trial1/B/
    • Trial2Controller
  • Examp (AreaRegistration)
    • Examp1Controller
      • Home ActionResult >>> /Examp/Examp1/Home/
      • A ActionResult; >>> /Examp/Examp1/A/
    • Examp2Controller
      • Home ActionResult >>> /Examp/Examp2/Home/
lstControllerActions Result:
  • Area -> Controller -> Action : Trial -> Trial1 -> Home
  • Area -> Controller -> Action : Trial -> Trial1 -> A
  • Area -> Controller -> Action : Trial -> Trial1 -> B
  • Area -> Controller -> Action : Trial -> Examp1 -> Home
  • Area -> Controller -> Action : Trial -> Examp1 -> A
  • Area -> Controller -> Action : Trial -> Examp2 -> Home
  • Area -> Controller -> Action : Examp-> Trial1 -> Home
  • Area -> Controller -> Action : Trial -> Trial1 -> A
  • Area -> Controller -> Action : Trial -> Trial1 -> B
  • Area -> Controller -> Action : Trial -> Examp1 -> Home
  • Area -> Controller -> Action : Trial -> Examp1 -> A
  • Area -> Controller -> Action : Trial -> Examp2 -> Home
Everything is beautiful but, No connection controller between area.
 
Thanks, What is your suggestion????

Answers (1)