Jerry Nixon on Windows: Can WebForms run in ASP.Net MVC?

Jerry Nixon on Windows

Tuesday, October 25, 2011

Can WebForms run in ASP.Net MVC?

Let’s just jump to the answer: yes.

So, here’s my simple MVC project. I selected an “Empty” MVC project. I added my empty Controller/HomeController.cs (all the defaults, just add and close) and an empty Home/Index.cshtml view.

Is there a simpler MVC application out there? One controller, one empty view.

Then I added my /Sample.aspx. It just writes out the date. No changes to the configuration. No extra Attributes on the classes. Not a single change whatsoever. And does it run? Yes. Are their limits, possibly – but this answers the basic question I have heard developers ask.


Let’s take just a moment to discuss if this is a good idea.

1. I suppose it is possible that you already have built and tested WebForm assets. If they are stand-alone or independent, it might make sense to contain them in the MVC project.

Note: You always have the option to put them in a separate project and run WebForms like normal, but perhaps you are wanting to take advantage of a single-sign-on scenario.

2. If you are making the switch to MVC you might not be able to afford the development cost or time for your entire application. This might be another argument to mix technologies.

Note: In the end, this is all the ASP.Net framework. This is fundamentally why this works out of the box. However, adopting MVC is typically a pattern decision – and you should defend it.

Here’s my conclusion on this brief discussion. MVC is a fun way for developers who are sick of web development to have a new tool. It has some IoC and Unit Testing benefits, I realize. But a mixed environment can’t be a long term, ideal solution. But it’s a nice choice in the short term.