将 webforms 项目转换为混合 MVC4 项目 [英] Convert a webforms project to a hybrid MVC4 project

查看:19
本文介绍了将 webforms 项目转换为混合 MVC4 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我们有一个旧式 ASP.NET 项目,大约有 800 个 .aspx 页面.

At the moment, we have an old style ASP.NET project that has around 800 .aspx pages.

随着时间的推移,我们正在考虑将其从 ASP.NET 网络表单迁移到 MVC4 + Razor,但不想放弃整个项目并重新开始.

We are looking at migrating this from ASP.NET webforms to MVC4 + Razor over time, but do not want to have to scrap the entire project and start again.

是否可以将项目文件转换为 MVC 项目并添加项目所需的文件/文件夹以作为 MVC 项目运行,但同时保留原始文件/文件夹结构允许现有/遗留仍以与现在相同的方式访问页面.

Is it possible to convert the project file to an MVC project and add the required files/folders for the project to run as an MVC project, but at the same time, preserving the original file/folder structure allowing the existing/legacy pages to still be accessed in the same way as they are now accessed.

推荐答案

是否可以将项目文件转换为MVC项目并添加项目作为 MVC 项目运行所需的文件/文件夹

Is it possible to convert the project file to an MVC project and add the required files/folders for the project to run as an MVC project

根据我在 VS2012 上使用数百个 .aspx 的 Web 应用程序项目的经验,在同一个应用程序中运行带有 razor 的 webforms 和 mvc 4 绝对是可能的.

Based on my experience with a Web Application project on VS2012 featuring several hundred .aspx, it is definitely possible to have webforms and mvc 4 with razor running in the same application.

我们没有修改项目文件(稍后会详细介绍).我们从一个裸 MVC4 应用程序开始,并在我们的 webforms 应用程序中复制了所需的功能.这包括:

We did not modify the project file (more on that later). We started from a bare MVC4 application and copied the needed features in our webforms application. This included :

  • 包和参考
  • web.config 中的指令(据我所知:无扩展处理程序、system.web.webPages.razor 元素和一些程序集绑定)
  • 大多数 global.asax 机制(即裸应用程序的路由)
  • 目录结构(模型、视图和控制器)

这是一项单调乏味的工作,但它也帮助我们了解了 MVC 项目的工作原理.我们仍然错过了一些 IDE 功能,例如右键单击时没有提供 MVC 组件(视图、控制器)-> 添加...我想这需要 csproj 编辑.我们没有走那么远.

This was a tedious work, but it also helped us understand what makes an MVC project work. We still miss some IDE features like not having MVC components (views, controllers) offered when right-click -> Add... I guess this would require a csproj editing. We did not go that far.

为了防止 url 冲突,MVC 通过几个专用区域使用,最终会替换相应的 webforms 文件夹.

To prevent conflicting urls, MVC is used through several dedicated areas which would, in the end, replace the corresponding webforms folders.

这篇关于将 webforms 项目转换为混合 MVC4 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆