且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将MVC集成到旧的ASP.NET应用程序中

更新时间:2022-11-05 21:32:49

你正在寻找它的过程不是集成而是升级。您需要将当前网站升级为新网站。一个非常简单的方法是创建一个新的ASP.NET MVC项目,然后在新项目中添加资源(HTML,CSS和JavaScript或其他后端代码)。



如果那是一个Web Forms项目,那么你将重新编写所有内容,因为两个模型都差别很大。您不能指望基于Master的项目在MVC架构上运行。



截至目前,Visual Studio 2012也(非常)陈旧。考虑升级到Visual Studio 2013或2015。
The process you are looking for it not "integrate" but "upgrade". You need to upgrade your current website to a new one. A very simple one is to create a new ASP.NET MVC project and then add the resources (HTML, CSS and JavaScript or other back-end code) in your new project.

If that was a Web Forms project then you are going to re-write everything, because both models are pretty much different. You cannot expect a Master-based project to run on an MVC architecture.

As of now, Visual Studio 2012 is also (very much) old. Consider upgrading yourself to Visual Studio 2013 or 2015.




最后我通过以下步骤成功实现了我的目标 -



1.我刚刚创建了一个新的Empty MVC项目。

2.现在我将我的ASP.NET网站的所有网页复制到我的新MVC项目中。

3.现在在我的MVC项目中手动添加所有引用。

4.右键单击Web Project然后单击转换为Web应用程序,这需要一些时间。您将看到一个新的designer.cs文件与每个.aspx页面相关联。

5.右键单击App_Code的所有类文件,您可能会看到新MVC中的Old_App_Code目录然后转到每个类文件的属性并从Build Action中选择Compile。

6.从旧web.config文件复制所有必需的设置并粘贴到解决方案内新web.config文件的所需位置。

7.现在构建你的新项目可能会发生一些可以手动修复的错误。现在一切都按预期工作了。



希望以上将适用于那些面临同样问题的人。我在这个解决方案中也使用了带有Linq to SQL的MVC,它对我有用。
Hi,
Finally i have successfully achieve my goal by doing following steps -

1. I just created a new Empty MVC project first.
2. Now i copied all the web pages of my ASP.NET website to my new MVC project.
3. Now added all the references manually in my MVC project.
4. Right click on Web Project then click on "Convert to Web Application", it takes some time. You will see that a new designer.cs file is associated with every .aspx page.
5. Right click on all the class files of "App_Code" you may be see "Old_App_Code" directory in new MVC project then goto properties of every class file and select Compile from Build Action.
6. Copy all the required setting from old web.config file and paste at desired location of new web.config file inside the solution.
7. Now build your new project may be some error will occurs which can be fixed manually. Now everything is working as expected.

Hope above will work for those who are faced same issue as i. I have also used MVC with Linq to SQL in this solution and it worked for me.