Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Is there a SharePoint equivalent of the Application_Start method in a class that derives from HttpApplication, such as the default Global class that is created when you add a Global.asax to an ASP.NET project?

I want to run some code when the SharePoint Web Application starts. Or is there a different preferred way of doing this in SharePoint?

In this particular case, I would like to run some code that does some expensive calculations and caches them. So this code would run on all front-end servers in the farm.

share|improve this question
    
SharePoint web application can be distributed across multiple servers. SharePoint functionality can be called not in context of web application. What problem you trying to solve? –  gandjustas Apr 12 '11 at 11:27
    
@gandjustas In this particular case, I would like to run some code that does some expensive calculations and caches them. So this code would run on all front-end servers in the farm. –  ScarePoint Apr 12 '11 at 12:28
    
You should use timer job for this. Or Custom Service Application if calculations involves databases or external services. –  gandjustas Apr 12 '11 at 12:33
add comment

3 Answers 3

Do you want the results in memory? or do you want to store them somewhere afterwards?

wouldnt mess with the Global handler approach as this is pretty complex to get right & is really hooking into the stack at the wrong level.

You want to hook in at the SharePoint Service App level by the sounds of it. This way you dont have to muck about with setup on new servers you add to the Farm etc... and its all managed through the same tools as the rest of the farm services.

share|improve this answer
add comment

I would suggest you move your code into a Timer Job that executes at regular intervals, in the background. Running stuff when the application starts will only slow down it further (we all know that SharePoint is a bit tired in the morning). Timer Jobs can be set to execute at specific intervals or times and can be run on specific or all servers.

Check out AC's post on the topic: http://www.andrewconnell.com/blog/archive/2007/01/10/5704.aspx (it's for MOSS 2007 but it's basically the same for 2010)

share|improve this answer
add comment

This will depend on what you want to achieve. One way would be to hook up a custom module.

Example http://www.sharepoint4arabs.com/AymanElHattab/Lists/Posts/Post.aspx?List=0b2c413e%2De6fb%2D4c60%2Da12f%2D9ae9bdbd48c8&ID=62

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.