Url.Action("LogOn") renders to /OrchardLocal/Contents/Item/LogOn instead of /OrchardLocal/Users/Account/LogOn

Topics: Customizing Orchard
Dec 3, 2012 at 10:58 AM
Edited Dec 3, 2012 at 11:01 AM

Edit: strange formatting applied to my post. I must be doing something wrong with including code in my post. Sorry about that



I'm trying to implement a custom login form and need a custom class on the form-tag so I can't use the @Html.BeginFormAntiForgeryPost and came up with the following:

<form action="@Url.Action("LogOn")" class="row" method="post">

@Html.TextBox("userNameOrEmail", "", new { id = "username-email", autofocus = "autofocus" })


<input type="submit" id="submit" value="OK">

The @Url.Action renders as: "/OrchardLocal/Contents/Item/LogOn". That should be "/OrchardLocal/Users/Account/LogOn" right?
When I look at the original LogOn.cshtml it uses the following code:
@using (Html.BeginFormAntiForgeryPost(Url.Action("LogOn", new { ReturnUrl = Request.QueryString["ReturnUrl"] }))) {
The Url.Action("LogOn") here renders correctly as seen in the resulting HTML: "/OrchardLocal/Users/Account/LogOn?ReturnUrl=%2FOrchardLocal%2"
When I hardcode "/OrchardLocal/Users/Account/LogOn?ReturnUrl=%2FOrchardLocal%2" as action in my form tag in my custom login form everything is working fine and I can login correctly when I hit the submit button.

The "/OrchardLocal/Contents/Item/LogOn" URL gives me an "The resource cannot be found" .NET error.
So, why is the @Url.Action("LogOn") rendering differently?
Kind regards.
Dec 3, 2012 at 11:17 AM

Is this in your Theme?

Dec 3, 2012 at 11:40 AM

Correct, this is in my custom theme.

Dec 3, 2012 at 11:46 AM

Its all based on routes. Orchard is matching the Login Action with the ReturnURL when it is passed, the problem is that you are passing a different route, which means orchard is picking that up. You basically need to pass a Return Url

Dec 3, 2012 at 2:14 PM
Edited Dec 3, 2012 at 2:15 PM

Like this? 

<form action="@Url.Action("LogOn", new { ReturnUrl = "/OrchardLocal/" })" class="row" method="post">

@Html.TextBox("userNameOrEmail", "", new { id = "username-email", autofocus = "autofocus" })


<input type="submit" id="submit" value="OK">


Same result, it renders as:

<form action="/OrchardLocal/Contents/Item/LogOn?ReturnUrl=%2FOrchardLocal%2F" class="row" method="post">
Dec 3, 2012 at 7:39 PM

You forgot to specify the area in Url.Action.

Dec 3, 2012 at 8:43 PM

Not only the Area, so I figured out.

I looked at the AccountController.cs in Orchard.Users and saw several construction of links such as this one:


Url.Action("LostPassword", "Account", new { Area = "Orchard.Users", nonce = nonce }) 

On line 207


So this is the adjusted version, it works now:


<form action="@Url.Action("LogOn", "Account", new { Area = "Orchard.Users", ReturnUrl = "/OrchardLocal/" })" class="row" method="post">



I'm rather new to Orchard(and Razor and MVC) but I like it! Especially the helpfull and quick! support. Thank you Jetski ad Bertrand!