Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Professional ASP.NET MVC 2
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET MVC 2
This is the forum to discuss the Wrox book Professional ASP.NET MVC 2 by Jon Galloway, Scott Hanselman, Phil Haack, Scott Guthrie, Rob Conery; ISBN: Professional ASP.NET MVC 2
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET MVC 2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old November 1st, 2010, 08:53 PM
Registered User
Join Date: Aug 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chpt 12: Including MVC in Existing Web Form Apps Yields no Results!

If anybody has some ideas about what I'm doing wrong, I would really appreciate it.

I have carefully followed the instruction in chapter 12: Including MVC in Existing Web Forms Applications and been unable to get this to work. I am using .NET 4 framework. I even downloaded the route debugger, which appears to show the correct routing information and I must conclude indicates the route engine is loading routes correctly. But a route-registered page always has an error message, although the regular web form pages display and work correctly. The error message I get is (ACCB is my application name):

The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /ACCB/Home

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
  #2 (permalink)  
Old November 1st, 2010, 10:05 PM
Friend of Wrox
Points: 539, Level: 8
Points: 539, Level: 8 Points: 539, Level: 8 Points: 539, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Oct 2010
Location: Seattle
Posts: 106
Thanks: 1
Thanked 17 Times in 17 Posts

I haven't looked at that chapter but I'll give it a shot. Can you show us (code) how you routed the page?

I'm guessing you made changes in Global.asax - what does the routing look like?
  #3 (permalink)  
Old November 2nd, 2010, 01:54 PM
Registered User
Join Date: Aug 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Routing done per pg. 447

Thanks for looking at this! I set up the routing exactly as described on pg. 447. I also installed the debugger as described on pg. 216. As a side note, Dino Esposito writes in his book, "Programming Microsoft ASP.NET MVC" on pg 75: "Hosting Web Forms pages in an ASP.NET MVC application is possible, but the opposite doesn't work. To process ASP.NET MVC extensionless URLs and resolve them in terms of controllers and view, you need to tweak the runtime environment and the folder structure to make the whole application just become a new ASP.NET MVC Application! So you're back to square one; you can mix Web Forms and MVC pages in an ASP.NET MVC project, but nothing else." I'm starting to move in that direction, although it is making me think twice about even deploying MVC2 at all.
  #4 (permalink)  
Old November 2nd, 2010, 04:43 PM
Registered User
Join Date: Aug 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default The steps for for a simple application!

OK, so I created a new vanilla webapplicaion with a simple default page. I then went through the steps from Chpt 12 and it worked as it should. The "Route Tester" (from Chpt 4, pg 216) Matched the Route correctly. However, it also Matches the route without erros from my full-blown web forms application, but then delivers an error page as described in my initial post. Something is not compatible with MVC2 in my web forms application. I need to somehow isolate this . . . . I'll post my findings later.
  #5 (permalink)  
Old November 30th, 2010, 03:30 PM
Registered User
Join Date: Aug 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Success at last! Microsoft pointed me in right direction!

After attempting without success to convert our existing, moderately complex Web forms application to an ennvironment that includes MVC2, I opened a trouble ticket with Microsoft in hopes that they could help me resolve the issue. The engineer who helped me was very aware of the instructions in Chapter 12 of "Professional ASP.NET MVC2." We walked through this together and he agreed that I had done everything correct. He took a day to study our code and concluded that the application must be converted from a Web Site Project (WSP) to a Web Application Project (WAP). In his own words, "MVC2 does not play well with WSP-based applications." Instead of starting out with my big project, I took a smaller WSP project and followed the instructions found on blogs.msdn.com for "Converting a Web Site Project to a Web Application Project." The instructions were very clear and straight-forward. I easily converted my simple app to WAP and then added in the MVC2 framework with no problems. It turns out that all of my projects I have worked on since Visual Studio 2005 have been WSP projects. I had not paid much attention to the difference between WAP and WSP. Since my projects had all been working quite well, I was happy to leave well enough alone. So I had to educate myself on the differences of WSP and WAP. There are many interesting blogs posted about this, including this one by Vishal Joshi:


I'm in the process of converting all my project to WAP for many of the reasons spelled out in Joshi's blog.

Next I returned to Chapter 12 and repeated the steps outlined and sure enough everything worked fine! Now I needed to convert my larger more complex application. This was not as straight forward as I had hoped.

After experimenting with this for a few days and discovering that I would need to perform a lot of steps I decided that I should break the project down into 8 mostly distinct steps. Each step included several tasks. To keep track of all this I used Visual Source Safe to keep acurate track of what I had completed and allow me to easily roll back to any of the steps. OK, so after performing the following steps, I succesfully created a WSP to WAP application that included MVC2 framework. It worked! Here are my steps, which reflect all of the issues I ran into (you may not run into these, or you may run into others). I was using Visual Studio 2010 Ultimate:

1. Create a new WSP project from my current project and bind to VSS. (Essentially, I branched my current WSP project for safety and to keep track of my steps).
2. During my experimentation I found that a previous programmer on the project had named one of the user controls the same name as one of the global classes. This is not a problem with WSP but conflicts in WAP. So, while still a WSP, I renamed the user control from "Product" to "ProductUC" so that it would not clash with the "Product Class". I then had to change all the code that referenced this user control with the wrong name. Again, checked this in to VSS to keep track of my steps.
3. Create a new empty WAP project within a new solution. Add the WSP project to the new solutions. So I have a solution (ITSol) an empy WAP project within the solutions (ITWap) and the WSP project to convert within the solution also (ITWsp).
4. My solution (ITSol) now contains two projects: ITWap and ITWsp. First I deleted the ITwap web.config file that had been created automatically. Next I added in all the assembly references from the ITWsp project (Right-click on the ITWap project icon and choose "Add Reference." From the "Add Reference" dialog, select "Browse" tab. Find the bin directory from the ITWsp project and select all the file.dll and click OK. This should add all your references to the ITWap project. Now copy all the code contained in the App_Code folder from the ITWsp to the ITWap. Right click on the ITWap App_Code directory and select "Convert to Web Application." You will notice that Visual Studio renamed your App_Code folder to Old_App_Code. If you don't understand why it did this, stop and do some research on how WAP projects are different from WSP projects before proceeding. After this step, I tracked my changes in VSS.
5. Copy all the application files from ITWsp to ITWap. I did not copy the Global.asax file over because I wanted to generate a new one using the "add new item --> global.asax file" within visual studio 2010. I then studied my WSP global.asax file and copy/pasted the content. (You may not need to do this, but our code had a lot going on in this file). Next, from the ITWap root node, choose "convert to web application."
6. Now attempt to build the application. In my case the new ITWap had many errors relating to our use of the "ProfileCommon" Class which we used in conjunction with the membership system. With a little research I learned that this would require some changes. The best information I found on this was a blog posted by Jon Galloway, "Writing a custom ASP.NET Profile class":


I carefully followed his instructions and successfully implemented a new UserProfile class based upon the ProfileBase.
7. Address build issues that a now exposed. OK, I'm no longer getting any "PofileCommon" build issues. Still, though, there are some minor build issues showing up. In my case, this included some objects of different types that had the same name. I had to go through the code and change these. For instance a view object named "LineItemsView" conflicted with a variable named "LINEITEMSVIEW." Also, during this process some of the Enterprise Library blocks we are using did not move over correctly and I needed to re-install these. Your issues, if any, may be different, but this is the point to tackle them. This is of course obvious, but I always find that very carefully reading the build error messages can lead to the solution. I have so often read only the first part of the message and attempted to fix it only to go back later and realize it actually contained more useful information in the detail. I also ran into some Theme issues, one of which I still haven't figured out. The ITWsp used menutabs in several places and the CSS applied to these is not gettinig picked up. But, the ITWap builds and generally runs correctly! Again VSS checkin.
8. Finally then: Install MVC2 framework to the ITWap and validate that both frameworks (Web Forms and MVC2) work correctly. For the first time ever, this worked correctly with my moderately complex web forms application!

I spent 2 solid weeks getting my WSP application converted to a WAP application that could incorporate the MVC2 framework. If you are having similar issues, I hope this posting will help you.

Last edited by jlakes; November 30th, 2010 at 04:19 PM.

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
CHPT 12, pg 374 & 360 grassang BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 0 August 8th, 2010 12:31 AM
Errors while upgrade theBeerHouse mvc project form asp.net mvc 1.0 to 2.0 vanbach1304 BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 0 April 20th, 2010 07:43 AM
Chpt. 12 - unable to configure modules using Start Kit Meister1867 BOOK: Professional DotNetNuke 5: Open Source Web Application for ASP.NET ISBN: 978-0-470-43870-1 0 August 25th, 2009 02:31 AM
Chpt 12 Bulk Copy smiller BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 1 February 13th, 2007 11:25 PM

All times are GMT -4. The time now is 02:29 AM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.