简体   繁体   English

是否可以将 ASP.NET ASPX 解决方案迁移到 ASP.NET Core 2.0?

[英]Is it at all possible to migrate ASP.NET ASPX solution to ASP.NET Core 2.0?

I want to migrate my asp.net (UI ASPX pages WebForms) application to ASP.NET Core 2. By some search I found out aspx is not supported in .net core.我想将我的 asp.net(UI ASPX 页面 WebForms)应用程序迁移到 ASP.NET Core 2。通过一些搜索,我发现 .net core 不支持 aspx。 If this is true(anyone has exact documentation for this?) how should anyone proceed to convert from pure asp.net aspx project to asp.net core 2.0?如果这是真的(有人对此有确切的文档吗?)任何人应该如何从纯 asp.net aspx 项目转换为 asp.net core 2.0?

I used portable analyzer tool but it is confusing to just give every.dll file and get report which is more confusing.我使用了便携式分析器工具,但只提供每个.dll 文件并获得更令人困惑的报告是令人困惑的。

Please give valid Microsoft document if possible.如果可能,请提供有效的 Microsoft 文档。

It all depends on what you mean by "migrate".这完全取决于您所说的“迁移”是什么意思。 As mentioned in the comments to your question, ASP.NET Core does not support web forms so there isn't any way to just automatically convert an a Web Forms website to an ASP.NET Core website.正如对您的问题的评论中提到的,ASP.NET Core 不支持 Web 表单,因此没有任何方法可以自动将 Web 表单网站转换为 ASP.NET Core 网站。

That said, it is possible to make the migration.也就是说,可以进行迁移。 I have been working to do just that for a very large web forms based website that I want to convert to ASP.NET Core.我一直在努力为一个非常大的基于 Web 表单的网站做这件事,我想将其转换为 ASP.NET Core。 If you are serious about making the journey, then here is some info that will probably help you.如果您真的想踏上旅程,那么这里的一些信息可能会对您有所帮助。

The general architecture of ASP.NET Core is based on MVC so it's much more similar to ASP.NET MVC than ASP.NET Web Forms. ASP.NET Core 的总体架构是基于 MVC 的,因此它更类似于 ASP.NET MVC 而不是 ASP.NET Web Forms。 So you will end up rewriting pretty much all of your UI code using some derivative of a MVC pattern.因此,您最终将使用某种 MVC 模式的派生物来重写几乎所有的 UI 代码。 Instead of master pages you will be using layouts.您将使用布局代替母版页。 Instead of server controls you will be using tag helpers.您将使用标签助手代替服务器控件。 Instead of user controls you will be using partials and view components.您将使用局部组件和视图组件代替用户控件。 Instead of code behinds you will be using controllers and view models.您将使用控制器和视图模型来代替代码隐藏。 Etc.等等。

It's worth noting that there is still an http context object, request object and response object and they are extremely similar to the analogous objects in web forms.值得注意的是,仍然有一个 http 上下文对象、请求对象和响应对象,它们与 Web 表单中的类似对象非常相似。 So that helps with the conversion.这有助于转换。

Also to make the conversion process easier, you can build an ASP.NET Core web application that targets the full framework.此外,为了简化转换过程,您可以构建一个以完整框架为目标的 ASP.NET Core Web 应用程序。 This means that you will have access to most everything you are use to in the full framework except anything in the System.Web namespace.这意味着除了 System.Web 命名空间中的任何内容之外,您将可以访问在完整框架中使用的大部分内容。 Targeting the Full framework does mean that your new website will only run on windows.针对完整框架确实意味着您的新网站将仅在 Windows 上运行。 But if you can live with that (at least for now) it will make the conversion process easier for you.但是,如果您能忍受(至少现在),那么转换过程对您来说会更容易。

If, in your old website, you broke out a bunch of the functionality into class libraries, that will make your life easier.如果在您的旧网站中,您将一堆功能分解到类库中,那将使您的生活更轻松。 You should be able to bring those class libraries over to the new website unchanged and reference them from the ASP.NET Core website and they will most likely work fine provided they don't reference System.Web.您应该能够将这些类库原封不动地带到新网站,并从 ASP.NET Core 网站引用它们,如果它们不引用 System.Web,它们很可能会正常工作。 Any code that does reference System.Web will need to be modified to use the new analogous objects or UI approaches.任何引用 System.Web 的代码都需要修改以使用新的类似对象或 UI 方法。

So in the end, you may be able to bring over your data models, data access code, business objects, and business logic without too much hassle.所以最后,您可以轻松地使用您的数据模型、数据访问代码、业务对象和业务逻辑。 But you will have to do a total rewrite of your UI related code.但是您将不得不完全重写与 UI 相关的代码。 That's the journey I'm on and it's not as hard as you might think, at least not once you get up to speed with ASP.NET Core in the first place.这就是我正在进行的旅程,它并不像您想象的那么难,至少在您一开始就熟悉 ASP.NET Core 之后不会。 Go get `em!去拿他们!

I found an article claiming that it's possible somehow.我发现一篇文章声称它有可能以某种方式实现。 As you know it's not easy to migrate entire project from WebForm to.Net Core instantly.如您所知,立即将整个项目从 WebForm 迁移到 .Net Core 并不容易。 So what if I be able to have my web form pages working on production and at the same time start to convert pages one by one gradually?那么,如果我能够让我的 Web 表单页面在生产环境中工作,同时开始逐渐一页一页地转换页面呢? I mean there are the combination of two approaches at the same project.我的意思是在同一个项目中结合了两种方法。

It's the idea that an open source named DotVVM proposes.这是一个名为DotVVM的开源项目提出的想法。 You have your ASP.Net web form pages and merely install DotVVM through Nuget.您拥有 ASP.Net Web 表单页面,并且仅通过 Nuget 安装 DotVVM。 DotVVM supports both approaches. DotVVM 支持这两种方法。 DotVVM contains similar controls like GridView, Repeater, FileUpload and more, you need to know about DotVVM syntax though. DotVVM 包含类似的控件,如 GridView、Repeater、FileUpload 等,但您需要了解 DotVVM 语法。

DotVVM can run side-by-side with other ASP.NET frameworks (Web Forms, MVC, Razor Pages) DotVVM 可以与其他 ASP.NET 框架(Web 窗体、MVC、Razor Pages)并行运行

it's claimed that:它声称:

If the business layer is separated properly, rewrite on one page takes about 1 hour in average.如果业务层分离得当,一页重写平均需要1小时左右。

After a few months (if your project is large), when all the ASPX pages are rewritten in DotVVM, you will be able to create a new ASP.NET Core project, move all DotVVM pages and viewmodels into it and use them with .NET Core.几个月后(如果你的项目很大),当所有的 ASPX 页面都在 DotVVM 中重写时,你将能够创建一个新的 ASP.NET Core 项目,将所有 DotVVM 页面和视图模型移动到其中并与.NET 一起使用它们核。 The syntax of DotVVM is the same on both platforms. DotVVM 的语法在两个平台上是相同的。

Here you can see five steps needed for the migration.在这里您可以看到迁移所需的五个步骤。

You can transfer all your business logic, models and even some controller methods (You just need to adjust those ActionResult to IActionResult).你可以转移你所有的业务逻辑、模型甚至一些控制器方法(你只需要将那些 ActionResult 调整为 IActionResult)。 If you're using Ninject (for ASP.NET Framework IOS), you just need to register them to your Startup.cs.如果您正在使用 Ninject(用于 ASP.NET Framework IOS),您只需将它们注册到您的 Startup.cs。 Basically, what I'm trying to say, you need to create a new application under .NET Core.基本上,我想说的是,您需要在 .NET Core 下创建一个新应用程序。 It would be changes in the actual project solution, but your actual business flow won't be different.会是实际项目方案的变化,但是你实际的业务流程不会有什么不同。 I hope this helps you.我希望这可以帮助你。

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

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