简体   繁体   English

在.net Framework应用程序中包括.net核心WebAPI?

[英]Including .net core WebAPI in .net framework application?

I am in the process of modernising a large .NET Framework web-based (vb.net) ERP system consisting of thousands of screens, I am considering recommending a slow shift of screens from a more traditional back-end HTML generation process to an Angular UI fed by a .NET Core WebAPI. 我正在现代化包含数千个屏幕的大型.NET Framework基于Web的(vb.net)ERP系统,我正在考虑建议将屏幕从较传统的后端HTML生成过程缓慢转移到Angular由.NET Core WebAPI填充的UI。

Is it true that I can develop a .NET Core WebAPI and compile for .NET Framework then run this within the same application pool as the rest of the existing application? 我是否可以开发.NET Core WebAPI并针对.NET Framework进行编译,然后在与现有应用程序其余部分相同的应用程序池中运行它,这是真的吗? I'm assuming I can handle routing sufficiently to separate old vs new pages, but the benefits of having access to the same session/application pool would simplify many problems down the line. 我假设我可以处理足够的路由以分隔旧页面和新页面,但是访问同一会话/应用程序池的好处将简化许多问题。

Old 'legacy' code would continue to be developed as is, but if any code required sharing between the two then it would be moved to the .NET Core project, compiled for .NET Framework and referenced in the legacy code. 旧的“遗留”代码将继续按原样开发,但是如果需要在两者之间共享任何代码,则将其移至.NET Core项目,为.NET Framework进行编译,并在旧代码中引用。 Is this a legitimate/possible development process? 这是合法/可能的开发过程吗?

Because things like sessions, auth, etc. involve encryption, applications can only "share" it if they can both somehow be configured to encrypt and decrypt things in the same way. 由于诸如会话,身份验证之类的事物都涉及加密,因此,只有将应用程序都可以以某种方式配置为对事物进行加密和解密,应用程序才能“共享”它。

For older ASP.NET applications, this was handled via the machine key. 对于较旧的ASP.NET应用程序,这是通过计算机密钥处理的。 You could simply set the same machine key in the Web.config for each application and then they could understand each other. 您只需在Web.config中为每个应用程序设置相同的机器密钥,然后它们就可以相互理解。

The problem here, though, is that ASP.NET and ASP.NET Core fundamentally handle things like sessions and even encryption differently. 但是,这里的问题是ASP.NET和ASP.NET Core 从根本上处理诸如会话甚至加密之类的事情。 While ASP.NET encrypts via the machine key, ASP.NET Core uses a data protection provider. 当ASP.NET通过机器密钥加密时,ASP.NET Core使用数据保护提供程序。 It doesn't know or care about machine keys; 它不知道也不关心机器密钥。 it doesn't even use Web.config for that. 它甚至不使用Web.config。 Then, to make matters worse, the actual mechanism of persisting session state is different, so even if you could somehow get them to be able to encrypt and decrypt each other's stuff, they wouldn't be able to understand the actual session data. 然后,更糟糕的是,持久保留会话状态的实际机制是不同的,因此,即使您能够以某种方式使它们能够加密和解密彼此的东西,它们也将无法理解实际的会话数据。

Long and short, no, you cannot share sessions between ASP.NET and ASP.NET Core apps. 总而言之,不,您不能在ASP.NET和ASP.NET Core应用程序之间共享会话。

Also, while you can potentially run both in the same App Pool (you can technically run whatever you want in the same App Pool), that doesn't buy you anything. 另外,尽管您可能都可以在同一个应用程序池中运行它们(从技术上讲,您可以在同一个应用程序池中运行任何内容),但这并不会给您带来任何好处。 Being in the same App Pool doesn't bestow any magical properties. 在同一个应用程序池中不会赋予任何神奇的属性。 On the contrary, being in the same App Pool simply ties the fates of your applications together. 相反,位于同一个应用程序池中只会将应用程序的命运联系在一起。 If one crashes, it'll likely take everything else in the pool with it. 如果发生崩溃,则很可能会将池中的其他所有内容都带走。 It's usually best to isolate apps in their own App Pool. 通常最好将应用隔离在自己的应用池中。

It is true that you can share the application pool between your applications, but you are wrong here regarding having access to Session within applications of the same application pool. 确实可以在应用程序之间共享应用程序池,但是在同一应用程序池的应用程序中可以访问Session的情况在这里是错误的。

Session object will always be different for each application. 会话对象对于每个应用程序总是不同的。

Apart from that, I don't see a benefit in sharing app pool in a long run. 除此之外,从长远来看,共享应用程序池不会带来任何好处。 As an issue in one of the application can impact other application running in the same app pool. 一个应用程序中的一个问题可能会影响在同一应用程序池中运行的其他应用程序。

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

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