本文介绍了有没有从Global.asax中的Owin Application_End?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<$c$c>Startup.cs是一种新的方式来初始化您的应用程序,而不是的Application_Start 在Global.asax中和它的罚款。但有一个地方把我拆卸的逻辑,比如这个:

Startup.cs is a new way to initialize your app instead of Application_Start in Global.asax and it's fine. But is there a place to put my teardown logic, for example this:

public class WebApiApplication : System.Web.HttpApplication
{
  protected void Application_End()
  {
    // Release you ServiceBroker listener
    SqlDependency.Stop(connString);
  }
}

看着 Microsoft.Owin 命名空间,但它只是似乎有 OwinStartupAttribute 。这是否意味着应用程序生命周期事件是由 System.Web.HttpApplication 仍在处理实例和不支持的OWIN规范?

Looked in Microsoft.Owin namespace but it only seems to have OwinStartupAttribute. Does this mean that application lifecycle events are still processed by System.Web.HttpApplication instance and are not supported by OWIN specification?

推荐答案

AppProperties Microsoft.Owin.BuilderProperties ,公开的CancellationToken OnAppDisposing

您可以得到这样的标记的和注册的回调的吧

You can get this token and register a callback to it

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        var properties = new AppProperties(app.Properties);
        CancellationToken token = properties.OnAppDisposing;
        if (token != CancellationToken.None)
        {
            token.Register(() =>
            {
                // do stuff
            });
        }
    }
}

这篇关于有没有从Global.asax中的Owin Application_End?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 10:20