Like any other ASP.NET application, the web app I'm developing depends on a plethora o开发者_运维问答f services and settings. Examples of services include third-party web services and examples of settings include SMTP server settings. It is fairly typical for a Java application to do some self checking at startup and if any of the required dependencies are not present or in the right state, the application will not start up. What is the best practice for implementing something similar in ASP.NET (MVC)?
See this: Use Bootstrapper in Your ASP.NET MVC Application and Reduce Code Smell
Note that you can extend the main interface there:
public interface IBootstrapperTask
{
void Execute();
bool IsEnabled(); // <--
}
and then only boot it if it says so.
Each service has its own way of checking for availability, and some services do not need to be checked at all unless there is a request for them. It really depends on the requirements of the application and the needs of the users.
if you have some depemdencies, you can do it at Application_Start and Session_Start to make such a check, both methods in Global.asax. If any severe error detected, you can redirect the page to an error message page and send an email to admin or log the error.
精彩评论