当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net - How to remove WebForms dependencies from an MVC application

问题描述:

I have a web application that began using WebForms. We've been steadily converting each page to use ASP.NET MVC instead, and we're finally just about done removing all WebForms dependencies entirely.

Are there any dependencies that get baked into a WebForms project, but which can be removed if we're only using MVC pages?

(I've found a post talking about how to remove the WebForms view engine, but I think that's talking about the MVC .ascx-based view renderers, which we haven't entirely eliminated yet.)

网友答案:

How to remove WebForms dependencies from an MVC application

It's simple, 3 steps:

  1. Ctrl+F for System.Web.UI in your entire solution. If you have more than 0 occurrences found you still have legacy code. Remove them. As a consequence of this removal your project won't probably compile => fix the compile time errors. Fixing the compile time errors doesn't mean anything yet. At runtime you might still hit glitches with some server side controls left in your views.

  2. Ctrl+F for runat="server" in your entire solution. If you have more than 0 occurrences found in a place other than a content placeholders you still have legacy code.

  3. Ctrl+F for HttpContext.Current in your entire solution. If you have more than 0 occurrences found you still have legacy code.

But the correct way to port a classic ASP.NET application to ASP.NET MVC is not by doing an in-place replacement. You will most certainly forget stuff. The correct approach is by starting from scratch. By using the Create New ASP.NET MVC 3 application wizard in Visual Studio and progressively migrating the code and views.

分享给朋友:
您可能感兴趣的文章:
随机阅读: