在sql 6应用程序中,如何启动和停止ASP.NET依赖关系?
在以前的版本中,您将使用Global.asax Application_Start事件,但是asp.net mvc 6没有此事件。
//Start SqlDependency with application initialization
SqlDependency.Start(connString);
// Stop SqlDependency
SqlDependency.Stop()发布于 2016-01-27 08:44:46
可以将启动代码放置在Startup.cs文件中。
试试像这样的东西
public class Startup {
public void Configure(IApplicationBuilder app, IApplicationLifetime lifetime) {
lifetime.ApplicationStarted.Register(() => {
//Start SqlDependency with application initialization
SqlDependency.Start(connString);
});
lifetime.ApplicationStopping.Register(() => {
// Stop SqlDependency
SqlDependency.Stop()
});
}
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}但是请注意,SqlDependency在dnx内核中不可用。
https://stackoverflow.com/questions/34971294
复制相似问题