how to call a method from Application_Start() in Global.asax.cs file when IIS server having particular site restarts in asp.net mvc5 application

Mayur Phase 0 Reputation points
2023-12-04T14:03:31.1566667+00:00

how to call a method from Application_Start() in Global.asax.cs file when IIS server having particular site restarts in asp.net mvc5 application?

Internet Information Services
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,630 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,413 questions
{count} votes

1 answer

Sort by: Most helpful
  1. XuDong Peng-MSFT 10,341 Reputation points Microsoft Vendor
    2023-12-05T10:18:00.6966667+00:00

    Hi @Mayur Phase,

    When I restart the application site from IIS server , I want to call WarmUpCache method but it is not working

    Based on your description, I think your main requirement is this, right? If this is the case, just try something like this:

    public static class SomeStartupClass
    {
        public static void Init()
        {
            // whatever code you need
        }
    }
    
    protected void Application_Start() 
    {     
    	AreaRegistration.RegisterAllAreas();
    	FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    	RouteConfig.RegisterRoutes(RouteTable.Routes);
    	BundleConfig.RegisterBundles(BundleTable.Bundles);
    	//something else what you need.
    	SomeStartupClass.Init(); 
    }
    

    And the Application_start method is executed when the web.config file changes or when the web server is restarted (or when the IIS application pool is manually recycled). In short, it is the entry point of the application and the user cannot call it manually.

    If I misunderstand anything, please let me know.

    Best regards,

    Xudong Peng


    If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.