I am using the MVC5 for an web application. The web app runs in IIS7 or greater.
In the Global.asax on application_start
, the number of licenses will be set:
protected void Application_Start()
{
try
{
MyApp.cNumberOfLicenses = COM.GetNumberOfLicenses();
}
catch(Exception e)
{
// log exception
// stop web site.
}
}
If any expection will be thrown in this context, the web site should shut down as you can do that in the IIS-Manager:
How can I stop the current web site in my Application_Start
?
I will go not with stop it, but to show some message if you do not have license.
This is an example, and an idea.
You can use this code on
global.asax
where if you do not have licenses the moment you start, you open a flag, and after that you do not allow any page to show, and you send a page that you can keep on an html file.You can have a file named
app_offline.htm
with content sayThis website is offline now
in web server and copy that to root directoy of website you want for any event.It will directly show that message, but yes, App pool will be still ON, when you need to start , you just need to rename that to something else.
You can do it with the help of "Microsoft.Web.Administration.dll"
After adding the reference of "Microsoft.Web.Administration.dll" write below code in Global.asax