如何使用 Webforms Web 应用程序项目中的 Razor Class 库

How to use Razor Class Library from a Webforms Web Application Project

作为迁移过程的一部分,我想在 WebForms 项目中使用 Razor Class Library。可能吗?

测试场景

包含三个项目的解决方案(由 Visual Studion 2017 15.7.2 创建):

在 CoreLibraryTest 中,我有 Areas/MyFeature/Page1.cshtml(由 VS2017 创建的结构)。在 Page1 正文中,我添加了一些文本(例如你好)。当我将对 CoreLibraryTest 的引用添加到 RazorPages、运行 RazorPages 并添加 /MyFeature/Page1到浏览器地址栏,它显示为页面。 WebForms 的相同过程将导致找不到 404 页面。

没有解决办法。无法从 Webforms Web 应用程序项目引用 Razor Class 库。

参考:

Razor Class Library is not routed properly when referenced from a WebForms project