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 5 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?

Windows development Internet Information Services
Developer technologies .NET Other
Developer technologies ASP.NET Other
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.