Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950
This is the forum to discuss the Wrox book ASP.NET MVC Website Programming Problem Design Solution by Nicholas Berardi, Al Katawazi, and Marco Bellinaso; ISBN: 9780470410950
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 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 August 10th, 2009, 11:53 AM
Authorized User
 
Join Date: Mar 2009
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
Default Chapter 5 UserController.cs P.119-129

I am following your book very closely except I have renamed the project MvcBeerHouse. Things went fine until I added the UserController.cs and then my Error List went wild. Where are the following classes for [Service, HttpPostOnly], TheBeerHouse.controllers.ServiceAttribute, ManagedFusion.Web.Mvc.HttpPostOnlyAttribute and namespaces defined? What's ManagedFusion.Web.Mvc?

Error 1 The type or namespace name 'ServiceAttribute' could not be found (are you missing a using directive or an assembly reference?) C:\Projects\MvcBeerHouse\Controllers\UserControlle r.cs 342 10 MvcBeerHouse
Error 2 The type or namespace name 'Service' could not be found (are you missing a using directive or an assembly reference?) C:\Projects\MvcBeerHouse\Controllers\UserControlle r.cs 342 10 MvcBeerHouse
Error 3 The type or namespace name 'HttpPostOnlyAttribute' could not be found (are you missing a using directive or an assembly reference?) C:\Projects\MvcBeerHouse\Controllers\UserControlle r.cs 342 19 MvcBeerHouse
Error 4 The type or namespace name 'HttpPostOnly' could not be found (are you missing a using directive or an assembly reference?) C:\Projects\MvcBeerHouse\Controllers\UserControlle r.cs 342 19 MvcBeerHouse
Error 5 The type or namespace name 'ServiceAttribute' could not be found (are you missing a using directive or an assembly reference?) C:\Projects\MvcBeerHouse\Controllers\UserControlle r.cs 373 10 MvcBeerHouse
Error 6 The type or namespace name 'Service' could not be found (are you missing a using directive or an assembly reference?) C:\Projects\MvcBeerHouse\Controllers\UserControlle r.cs 373 10 MvcBeerHouse
Error 7 The type or namespace name 'HttpPostOnlyAttribute' could not be found (are you missing a using directive or an assembly reference?) C:\Projects\MvcBeerHouse\Controllers\UserControlle r.cs 373 19 MvcBeerHouse
Error 8 The type or namespace name 'HttpPostOnly' could not be found (are you missing a using directive or an assembly reference?) C:\Projects\MvcBeerHouse\Controllers\UserControlle r.cs 373 19 MvcBeerHouse
Error 9 No overload for method 'Redirect' takes '2' arguments C:\Projects\MvcBeerHouse\Controllers\UserControlle r.cs 105 40 MvcBeerHouse
Error 10 No overload for method 'Redirect' takes '2' arguments C:\Projects\MvcBeerHouse\Controllers\UserControlle r.cs 107 40 MvcBeerHouse
  #2 (permalink)  
Old August 10th, 2009, 02:03 PM
fjp fjp is offline
Registered User
 
Join Date: Aug 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi. I am trying to create a new MVC Project too and I get the error #9 and #10 everytime I use the 'Redirect' method. As far as I see, the definition of 'Redirect' method in my new project is inside System.Web.Mvc.Controller.cs [from metadata], but the same method has its definition (as extension) in System.Web.Mvc.ControllerExtensions.cs [from metadata] in the original project. Did I miss something? Any help is welcome.
  #3 (permalink)  
Old August 10th, 2009, 02:06 PM
nberardi's Avatar
Wrox Author
 
Join Date: Aug 2008
Location: Phoenixville, PA, USA
Posts: 102
Thanks: 1
Thanked 16 Times in 16 Posts
Send a message via AIM to nberardi
Default

Please make sure to download the latest code from CodePlex.

http://thebeerhouse.codeplex.com

It contains the necessary assembly to get that code working.
__________________
Check out my blog at: http://www.coderjournal.com
  #4 (permalink)  
Old August 10th, 2009, 04:19 PM
Authorized User
 
Join Date: Mar 2009
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
Default Chapter 5 UserController.cs P.119-129

Hey Nick

Thanks for the quick response.
I have the latest download and there's no issue with that. The problem is with neophytes like me. I am using your book as a learning textbook and there are a lot of implied steps I'm having to research. For example, the Resource file ManagedFusion.Web.dll needs to be added to the project to get rid of the errors I listed earlier in my thread. I'm starting this project from scratch...not reverse engineering TheBeerHouse, but I'm ending up having to work backwards just to see how things are done. Otherwise, I could have just downloaded the code without buying the book.

Where can I find more info on ManagedFusion.Web.dll?
  #5 (permalink)  
Old August 10th, 2009, 04:46 PM
nberardi's Avatar
Wrox Author
 
Join Date: Aug 2008
Location: Phoenixville, PA, USA
Posts: 102
Thanks: 1
Thanked 16 Times in 16 Posts
Send a message via AIM to nberardi
Default

That is totally understood, but think of the ManagedFusion.Web.dll as a resource, much like the style sheets, images, or anything else that are not easily transferred through a book.

At the time of writing the book, there were many things that MVC was lacking that are necessary to have a good website. Mostly because it is still in it's first release, and the MVC team gave us the basic framework, but not necessarily all the tools to complete the job.

While we were writing the book, we didn't know what the MVC team was going to introduce and what they were going to hold off for a future release. So it was a tricky process writing the book and keeping up with the new MVC releases. We ended up stripping out about 75% of the original functionality of ManagedFusion.Web.dll because it was deprecated in favor of the MVC code that did a similar functions.

Also there was a conscious decision to help grow the readers knowledge, especially for beginners. If we jumped right in to creating ActionFilters and specialized ActionResults for handling JSON content and other things, before we introduced basic concepts and the constructs of a proper controller, we would alienate many of the readers because the flow of the text would be confusing.

We hope to eventually fully remove ManagedFusion.Web.dll from the project, in favor of some more chapters or when MVC fully deprecates all the features it provides. That is if there is an MVC 2.0 Website Programming book.

Wish you the best,
Nick
__________________
Check out my blog at: http://www.coderjournal.com
  #6 (permalink)  
Old August 10th, 2009, 05:04 PM
Authorized User
 
Join Date: Mar 2009
Posts: 15
Thanks: 2
Thanked 0 Times in 0 Posts
Thumbs up Chapter 5 UserController.cs P.119-129

Hey Nick

I fully understand. As I go through your book and Pro ASP.NET 1.0 I'm not sure how I would organize the material. I think you guys did a great job and...don't get me wrong, I never regret buying your book because of the wealth of other info I get from it. And I think that's part of the problem. There's so much info that's changing so fast I can hardly keep up. Just look at the number of books WROX is publishing this year.

I love your book and am looking forward to your next venture.

Thanks for your help,
Ralph
  #7 (permalink)  
Old August 11th, 2009, 10:51 AM
Wrox Author
 
Join Date: Aug 2008
Location: Pittsford, NY, USA.
Posts: 19
Thanks: 1
Thanked 4 Times in 4 Posts
Send a message via AIM to Al_Katawazi
Default

I was curious so I removed the managed fusion DLL just to see what would happen. I have been using the user control for a lot of other projects and did not need the managed fusion dll and here is what I was able to piece together for you.

The User Controller has about 3 or 4 errors pertaining to the service httpPostOnly attribute flag. If you replace that with this:

[AcceptVerbs(HttpVerbs.Post)]

As for the other errors they pertain to the redirect method. You can easily replace that with a Redirect or RedirectToAction method to get the result you are looking for. In terms of the rest of the project, I think most of the errors are similar.
  #8 (permalink)  
Old August 11th, 2009, 11:07 AM
nberardi's Avatar
Wrox Author
 
Join Date: Aug 2008
Location: Phoenixville, PA, USA
Posts: 102
Thanks: 1
Thanked 16 Times in 16 Posts
Send a message via AIM to nberardi
Default

Quote:
Originally Posted by Al_Katawazi View Post
The User Controller has about 3 or 4 errors pertaining to the service httpPostOnly attribute flag. If you replace that with this:

[AcceptVerbs(HttpVerbs.Post)]
Actually Al is not correct about this, HttpPostOnly and AcceptVerbs(HttpVerbs.Post) serve two different functionalities, and it is wrong to equate the two.

AcceptVerbs is what is known as an action method selector, it inherits from the ActionMethodSelectorAttribute and is used as a pre-processor when the route is looking for the correct action method to use in conjunction with the current URL being requested. In the case of AcceptVerbs it compares the HTTP Verb (GET, POST, OPTIONS, DELETE, etc) to the verb that is being requested from Request.HttpMethod.

http://aspnet.codeplex.com/SourceCon...w/23011#266431

There is a problem with this in that if you don't have another action method with the same name, then the route will just skip by this. And might pick up another action method farther down the line. This can cause serious problems in your application, in that the chosen action method is now out of your hands, and it might happen on an action method that it wasn't suppose to and expose some serious problems. So please when ever you implement the AcceptVerbs attribute, make sure you at least account for GET and POST, if not all the other HTTP Verbs. Because if this is not thoroughly tested with all of them you could be opening up your application for a world of hurt.

See my Issue I posted to the ASP.NET team specifically about this issue.

However HttpPostOnly works differently in that it doesn't interrupt the route from finding the controller, it just throws the proper HTTP error response when the wrong Verb is used with the action method. Which is 405 Method Not Allowed and then responds with the methods allowed.

Here is the core of the HttpPostOnly.
http://code.google.com/p/coderjourna...lowedResult.cs

Quote:
Originally Posted by Al_Katawazi View Post
As for the other errors they pertain to the redirect method. You can easily replace that with a Redirect or RedirectToAction method to get the result you are looking for. In terms of the rest of the project, I think most of the errors are similar.
This is another place MVC was lacking and if you want proper handling of URL's you must keep the functionality of ManagedFusion.Web.dll. You can't simple replace it with Redirect or RedirectToAction, because they use the 302 Temporary Redirect, and what you actually want is a 301 Permident redirect. If you use a 302 redirect search bots don't update their URL to the new URL, and they keep the old one and the new one indexed in their system. However with a 301 redirect a search bot knows you want to move the URL, and they only keep the new one indexed.

This is important so you don't suffer from duplicate content penalties.
__________________
Check out my blog at: http://www.coderjournal.com

Last edited by nberardi; August 11th, 2009 at 11:43 AM.
  #9 (permalink)  
Old August 11th, 2009, 11:41 AM
Wrox Author
 
Join Date: Aug 2008
Location: Pittsford, NY, USA.
Posts: 19
Thanks: 1
Thanked 4 Times in 4 Posts
Send a message via AIM to Al_Katawazi
Default

I'm sorry Nick I haven't delved that much into what exactly is happening with the ManagedFussion.dll, I assumed the functionality was similar to the MVC Framework attribute flags and methods.

In reference to ralphs situation though, he can use either or. True you will not get the most elegant responses or functionality with the MVC Framework methods but they are part of the framework unless you propose he include the a managed fusion dll in all his new projects. Not that I am saying there is anything wrong with that since the source is out there but if ralph wants to stay within the framework those are some good alternatives.
  #10 (permalink)  
Old August 11th, 2009, 12:16 PM
nberardi's Avatar
Wrox Author
 
Join Date: Aug 2008
Location: Phoenixville, PA, USA
Posts: 102
Thanks: 1
Thanked 16 Times in 16 Posts
Send a message via AIM to nberardi
Default

Quote:
Originally Posted by Al_Katawazi View Post
I'm sorry Nick I haven't delved that much into what exactly is happening with the ManagedFussion.dll, I assumed the functionality was similar to the MVC Framework attribute flags and methods.

In reference to ralphs situation though, he can use either or. True you will not get the most elegant responses or functionality with the MVC Framework methods but they are part of the framework unless you propose he include the a managed fusion dll in all his new projects. Not that I am saying there is anything wrong with that since the source is out there but if ralph wants to stay within the framework those are some good alternatives.
If you really want to move away from ManagedFusion.Web.dll, copy the files to your local project. (it can be found here)

Al is wrong in equating the two because, AcceptVerb is a URL processor helper, and AcceptVerb should be used in these cases:

[AcceptVerb("GET")] public ActionResult GetList (int id) { ... }
[AcceptVerb("POST"] public ActionResult UpdateList(int id, string[] list) { ... }

And HttpPostOnly or anything in the AllowedHttpMethodAtribute class are security related functions. Equating the two is like saying URL Rewriting is like Forms Authentication, they are not even in the same ball park. And it is critical that you don't use AcceptVerb as a security measure, which is why I created the HttpPostOnly attribute.
__________________
Check out my blog at: http://www.coderjournal.com
 


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
Chapter 7 Object reference error in master.cs mikeal_a BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 4 September 5th, 2008 08:19 AM
Chapter 4 pp. 118-119 luciano991 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 August 13th, 2006 02:56 PM
Chapter 5 P 129 jmurdock BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 June 16th, 2004 03:46 PM



All times are GMT -4. The time now is 07:56 AM.


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