如何以编程方式停止当前网站?

编程入门 行业动态 更新时间:2024-10-28 12:25:54
本文介绍了如何以编程方式停止当前网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在将MVC5用于Web应用程序。该Web应用程序在IIS7或更高版本中运行。

I am using the MVC5 for an web application. The web app runs in IIS7 or greater.

在 application_start 的Global.asax中,将设置许可证数量:

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. } }

如果在这种情况下会产生任何期望,网站应该关闭,因为您可以在IIS管理器中执行以下操作:

If any expection will be thrown in this context, the web site should shut down as you can do that in the IIS-Manager:

如何在 Application_Start 中停止当前网站?

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.

您可以在 global.asax上使用此代码。 如果您在开始时没有许可证,请打开一个标志,然后再不允许显示任何页面,然后发送可以保留html文件的页面。

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.

private static bool fGotLicense = true; protected void Application_Start() { try { MyApp.cNumberOfLicenses = COM.GetNumberOfLicenses(); } catch(Exception e) { // log exception // stop web site. fGotLicense = false; } } protected void Application_BeginRequest(Object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; // if not have license - let show some infos if (!fGotLicens) { // the file we look now is the app_offline_alt.htm string cOffLineFile = HttpRuntime.AppDomainAppPath + "app_offline_alt.htm"; // if exist on root if (System.IO.File.Exists(cOffLineFile)) { using (var fp = System.IO.File.OpenText(cOffLineFile)) { // read it and send it to the browser app.Response.Write(fp.ReadToEnd()); fp.Close(); } } // and stop the rest of processing app.Response.End(); return; } }

更多推荐

如何以编程方式停止当前网站?

本文发布于:2023-11-03 13:37:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555253.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   网站

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!