Caleb Jares
Caleb Jares

Reputation: 6307

"Main" method in ASP.Net MVC Project - aka method to run before pages are loaded?

I have a project that is basically only an MVC project because it gives intellisense for Razor views and the library (Mvc.Mailer) depends on HttpContext. Right now I have to load a page in order for the constructor in my MvcApplication to run, or the Application_Start, or Init.

Is there a way to bootstrap the mvc app main method, or anything that is called before any page requests that doesn't require me to send a page load request?

Upvotes: 8

Views: 5890

Answers (4)

UserX
UserX

Reputation: 525

According to this: What is a composition root in the context of Dependency Injection

You can use Global.asax.cs which runs when an ASP.NET MVC project is started. I just verified this in my ASP.NET MVC project.

Upvotes: 4

LINQ Newbee
LINQ Newbee

Reputation: 333

override the OnActionExecuting() of your controller. It is called every time a page is called.

Upvotes: 0

Joachim Isaksson
Joachim Isaksson

Reputation: 180917

There's no method in ASP.NET that runs before the first access to your application.

The simplest way to fix it is to install AppFabric into your IIS and let that handle the automatic start of your services. It will "poke" all services it's configured with so that they're always running and initialized.

Upvotes: 3

user32826
user32826

Reputation:

Use the AutoStart feature of AppFabric to prewarm the AppPool, which will achieve what you want.

http://msdn.microsoft.com/en-us/library/ee677260.aspx

Upvotes: 1

Related Questions