我正在将 MVC 5 用于 Web 应用程序。 Web 应用程序在 IIS 7 或更高版本中运行。
在 Global.asax 上application_start
,将设置许可证数量:
protected void Application_Start()
{
try
{
MyApp.cNumberOfLicenses = COM.GetNumberOfLicenses();
}
catch(Exception e)
{
// log exception
// stop web site.
}
}
如果在此上下文中出现任何预期,则该网站应关闭,您可以在 IIS 管理器中执行此操作:
如何停止我的当前网站Application_Start
?
您可以借助“Microsoft.Web.Administration.dll”来完成此操作
using Microsoft.Web.Administration;
添加“Microsoft.Web.Administration.dll”的引用后,在 Global.asax 中写入以下代码
protected void Application_Start(object sender, EventArgs e)
{
try
{
MyApp.cNumberOfLicenses = COM.GetNumberOfLicenses();
}
catch (Exception e)
{
// get the web site name
var lWebSiteName = System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName();
// log exception
// stop web site.
using (ServerManager smg = new ServerManager())
{
var site = smg.Sites.FirstOrDefault(s => s.Name == lWebSiteName);
if (site != null)
{
//stop the site...
site.Stop();
}
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)