简体   繁体   English

在asp.net应用程序结束页面上查看计数数据未更新

[英]On asp.net application end page view count data in not updating

I have asp.net application. 我有asp.net应用程序。 I am forcibly end this application and on the time of that i want to update my view page count value in database. 我强行结束此应用程序,并希望在此时间更新数据库中的视图页面计数值。 If anyone known plz help me. 如果有人知道请帮助我。 I also written code in global.asax file 我也在global.asax文件中编写了代码

void Application_End(object sender, EventArgs e)
{
   // Code that runs on application shut`enter code here`down
}

but this is not working when i forcibly end application. 但这在我强制结束应用程序时不起作用。

I don't think that this is a very idea to try to save the data upon exiting if it's important to you. 我认为这对您很重要,在退出时尝试保存数据并不是一个好主意。

If you still want to try and you use .NET Framework 4.5.1, you can listen to the HostingEnvironment.StopListening event, which fires when an application shut down is pending: 如果您仍然想尝试并使用.NET Framework 4.5.1,则可以侦听HostingEnvironment.StopListening事件,该事件在应用程序关闭待决时触发:

void Application_Start(object sender, EventArgs e)
{
    HostingEnvironment.StopListening += (o, args) => SaveTheDataHere();
}

This will save the data if the hosting environment is shut down in an orderly manner, not if it abruptly crashes. 如果托管环境有序地关闭,则将保存数据,而不是突然崩溃。

Needless to say, this won't fire if there is a fire in the server room, a BSOD halts the OS, someone trips over a power cable, etc. 不用说,如果服务器机房发生火灾,BSOD停止操作系统,有人通过电源线跳闸等情况,则不会触发。

A better approach would be to offload the visit event (count) immediately or periodically (depending on what level of potential data loss i acceptable) to some error resilient external process, such as a message queue. 更好的方法是将访问事件(计数)立即或定期(取决于我可以接受的潜在数据丢失级别)转移给具有一定容错能力的外部流程,例如消息队列。

I got my answer, 我得到了答案,

void Application_End(object sender, EventArgs e)
{
   // Code that runs on application shut`enter code here`down
}

this event works only when the following things happens then fire. 此事件仅在发生以下情况然后触发时起作用。

  1. Update web.config. 更新web.config。

  2. Update dll file in BIN. 更新BIN中的dll文件。

  3. Stop OR restart IIS. 停止或重新启动IIS。

  4. Application pool recycle. 应用程序池回收。

So i implemented a web service for this to update my records in database periodically. 因此,我为此实现了一个Web服务,以定期更新数据库中的记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM