Forums - C# Corner

Forum guidelines
Aakash N

Aakash N

  • 1.7k
  • 128
  • 1.9k

.Net Core Call controller from another controller [Areas]

Jan 10 2019 2:41 PM
In my ASP.Net Core 2.1 solution(layout) I have areas as projects with its own controllers. On the layout solution home controller, I'm setting the session variables on Sql Server. and using session variables on areas where the data gets loaded. This is to avoid duplicating session logic on areas

In this case, I'm trying to launch area controller as startup and want to make areas controller wait until layout controller is ready with session variables set on Sql Server.
current routing on startup.cs
  1. app.UseMvc(routes =>
  2. {
  3. routes.MapRoute(
  4. name: "area",
  5. template: "{area:exists}/{controller=Area1Home}/{action=Index}/{id?}");
  6. routes.MapRoute(
  7. name: "default",
  8. template: "{controller=Home}/{action=Index}/{id?}");
  9. }); 
How can I make an area controller load on startup(landing page)?

Also, how can I make a make an area controller dependent on layout controller so that the application doesn't throw an error because session variables are not available to area controllers to load data? Or
Is there a way to make area controller wait until the home controller is loaded?