Saturday, March 28, 2009

Hybrid ASP.NET MVC and WebForms app

I'm in the process of adding ASP.NET MVC to an existing ASP.NET WebForms app in Visual Studio 2008. One of the neat features of an ASP.NET MVC app is that when you right click on the Controllers folder in the Solution Explorer the "Add" menu item has a "Controller..." menu item on it and right clicking on the Views folder causes the "Add" menu item to have a "View..." sub-menu item on it.

It took me forever to work out how to get my WebForms app to also show those menu items. It turns out that you have to edit the .csproj file for the WebForms app and find the section that reads:

<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

The to that add the following GUID:

{603c0e0b-db56-11dc-be95-000d561079b0};

Such that it now reads as follows:

<ProjectTypeGuids>{603c0e0b-db56-11dc-be95-000d561079b0};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

4 comments:

  1. How does it even work to have ASP.net MVC and Web Forms in a single application? Does it go to the MVC router first and fall back to the web forms, or the other way around? Are there any major issues with writing a hybrid application?

    ReplyDelete
  2. In the MVC route mapper you can elect to ignore *.aspx pages so it will got straight to those pages. I believe that it checks the route first. I haven't come across any issues yet but if I do I'll blog them.

    ReplyDelete
  3. Thanks for the info! I'm glad to hear that this sort of thing is supported by default.

    ReplyDelete
  4. For MVC3 use {E53F8FEA-EAE0-44A6-8774-FFD645390401};

    ReplyDelete