1

Can anyone spot the problem with this code?

View:

@model Tuple<LoginModel, RegisterModel>

<h2>Index</h2>

@using (Html.BeginForm("Login", "Login", FormMethod.Post))
{
    @Html.TextBoxFor(tuple => tuple.Item1.User, new { @Name = "User" })         
    @Html.PasswordFor(tuple => tuple.Item1.Password, new { @Name = "Password" })

    <button type="submit" name="Login">Connect</button>
}

@using .... Other actions.....

Controller:

    [Authorize]
    public class LoginController : Controller
    {
        //
        // GET: /Login
        [AllowAnonymous]
        public ActionResult Index(string returnUrl)
        {
            return View();
        }

        //
        // POST: /Login
        [HttpPost]
        [AllowAnonymous]
        public ActionResult Login(LoginModel model, string returnUrl)
        {
              .
              .
        }

The Login method does not get called and I'm having a hard time finding out why. If I rename the action to Index, it gets called... Can anyone spot the problem here?

I appreciate any feed back.

Regards, Fábio

Edit: It seems this is a permission issue. Even though the Login method contains the AllowAnonymous attribute, it still is not allowed to be called. If I first perform the login and then try to trigger the action, it works. Now, How do I make sure this action is allowed by unauthenticated users? Tried both adding the path to root web.config file and adding a web.config file authorizing everyon on Login folder. None worked.

Thanks again for the help.

Fábio
  • 505
  • 5
  • 9

2 Answers2

0

Ok, I managed to solve the issue by removing the authorization element from the root web.config:

<authorization>
   <deny users="?"/>
</authorization>

It is still unclear to me how this setting conflicts with MVC architecture. I used this so resources should be authorized to the public explicitly (not limited to actions and views).

What's even stranger is the odd behavior with one action being allowed and not the other.

I will surely adapt to the MVC way for other types of resources. I wish that would work fine with MVC.

Thanks everyone for taking the time to look into this. I appreciate.

I hope this helps someone else.

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Fábio
  • 505
  • 5
  • 9
-1

You haven't included the returnUrl parameter in your POST

EDIT:

You are changing the input names in your Razor. This is probably confusing the ModelBinder so it isn't creating a LoginModel.

matt-dot-net
  • 4,204
  • 21
  • 24
  • That's not really the problem. If I remove the returnUrl parameter from the Login method, it still does not get called. Besides, it is optional. – Fábio Jun 07 '13 at 14:53
  • @Fábio my apologies, i forgot that it was not required. Check my Edit – matt-dot-net Jun 07 '13 at 15:26
  • Thanks Matt, but I'm actually reassigning the members name because I'm using a View with two models, so the names reflect the properties of the model of the action being called. Edit: I am doing something like this http://stackoverflow.com/a/13823027/2463546 – Fábio Jun 07 '13 at 16:54