p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 (http://p2p.wrox.com/forumdisplay.php?f=472)
-   -   Chapter 5 UserController.cs P.119-129 (http://p2p.wrox.com/showthread.php?t=75635)

nberardi May 31st, 2010 12:05 AM

Quote:

Originally Posted by fourpastmidnight (Post 258567)
Now, in version MVC 1.0, this "may" have been true (most certainly it was true for MVC 1.0 PR, which the book uses, I don't doubt that). However, in MVC 2.0, this is a new change. (maybe?) From what I've read, HttpPostAttribute only accepts HTTP POST verbs according to the changes FAQ on asp.net: http://www.asp.net/learn/whitepapers...t-mvc#_TOC3_12..

You should take a look at it again. It does only allow HTTP POST requests now, if defined. So in that case it is working fine.

The problem, that you are failing to realize, is that it doesn't follow HTTP standards, specifically around the HTTP 405 method not allowed.

http://www.checkupdown.com/status/E405.html

Which is critical for some REST applications to function. Currently it returns an HTTP 404 Not Found response, which is totally wrong if they are trying to shoot for standards.

http://www.checkupdown.com/status/E404.html

If you read 404 specs, it only applies to the URL, not the method used against the URL. The 405 response defines how the method should be responded to if not currently defined or allowed.

This has been my biggest problem with the MVC team, they sit back and talk about how standards compliment MVC is, and everybody is willing to just gobble it up, because they really want to believe it is true, and with out doing any research to make sure it is true. Don't worry you are not the only one who has made this mistake. And in the process of everybody talking about how standards compliment MVC is they are actually bastardizing the standard because none of them over their want to read or take the time to actually understand something as basic as HTTP status codes.

So if you want standards compliment code you still have to use my HttpPostOnly attribute, if you don't care, then use HttpPost.

As I stated before, we never mentioned ManagedFusion.dll in the whole book, because we totally expected it to be obsolete by publishing, but the MVC team has continued to let us down for a couple small features that makes your application that much more in line with standards. And me and Al weren't going to compromise on putting out crap, just because the MVC team doesn't understand the difference between a 404 and a 405.

fourpastmidnight May 31st, 2010 09:13 AM

HTTP Post Only Actions
 
Nick:

Wow! Thanks for the reply. Apparently, there is much more to this than just making sure you accept only HTTP POST verbs. I'm relatively "new" to Web programming. I understand the basics (which is probably what 80% of all "web programmers" really understand, if you think about it). I had no idea that the 404 would be returned through MS's attribute.

I am aware of most of the HTTP error codes, but 405 is not one of them. That's interesting. Thanks again, I am truly here to learn. Guess I should get my hands on the HTTP spec and check MS's code for what they're doing. It's unfortunate that I can't trust them to create "compliant" code when that's what they're touting.

Guess I'll be hooking back up ManagedFusion.Web.Mvc.dll. [;)]

ulikkg June 14th, 2010 01:53 PM

error in HTML.IF
 
I want to use membership part in another project. When I followed this chapter in TheBeerHouse project I did not face but in this new project I am facing. Could somebody please help?

I created Register method inside UserController. Then without doing other Logi, ManageUsers etc methods I continued with Register View. When I run application I am getting following error:

Compiler Error Message: CS1061:
'System.Web.Mvc.HtmlHelper<object>' does not contain a definition for 'If' and no extension method 'If' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<object>' could be found (are you missing a using directive or an assembly reference?)


for


Line 13: <form method = "post" action = "<%= Url.Action("Register", "User") %>"
Line 14: <input type="hidden" name="returnUrl" value="<%= Html.If(!String.IsNullOrEmpty(Request.QueryString["returnUrl"]), () => Request.QueryString["returnUrl"])
Line 15: .ElseIf(Request.UrlReferrer != null, () => Request.UrlReferrer.ToString())
Line 16: .Else(() => String.Empty) %>"/>


Please help.

fourpastmidnight June 16th, 2010 09:05 PM

HtmlHelper.If
 
Ulikkg:

The HtmlHelper.If method is not (to my knowledge) a standard .NET Base Class Library class. IIRC, this method is in one of the ManagedFusion.Web.*.dll files that came with the source code for the book (and which IIRC is freely downloadable and usable in your own projects). If it's not in ManagedFusion, it's in one of the other 3rd Party libraries.

I hope from what I've posted you can find this method.

Even if you can't, you don't need it. That method is just a nice way of doing If/Else constructs without all the "Classic ASP"-looking spaghetti code; but don't get me wrong, in the context of ASP.NET MVC, there's nothing wrong with the following code:

Code:

<% if (/* my boolean expression condition */ ) { %>
  <!-- Put some other ASP.NET code and/or HTML here. -->
<% } else { %>
  <!-- Do something else. -->
<% } %>

HTH.

M3rcuryKT February 19th, 2011 10:40 PM

Quote:

Next, right-click the project and, IIRC, there is' an Edit Project item. In any event, it will open up the XML file that resembles your project. Locate the following XML:
What is IIRC?

Still not clear about how to fix this, I've got the same Iso3166CountryCodes problem over "Properties" (does not exist in current context)


string[] iso3166 = Properties.Resources.Iso3166CountryCodes.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

Am I missing something? Any feedback is appreciated, thank you.


All times are GMT -4. The time now is 04:43 PM.

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