views:

221

answers:

2

I have a Logon page in a MVC (1.0) application that I am securing with SSL, I have an attribute that inspects the request for the page and redirects to a https uri when it is requested with http. This all works, however when I post the form content i get the following error:

The parameters dictionary contains a null entry for parameter 'rememberMe' of non-nullable type 'System.Boolean' for method 'System.Web.Mvc.ActionResult LogOn(System.String, System.String, Boolean, System.String)' in 'DAC.US.Web.Portal.Controllers.AccountController'. To make a parameter optional its type should be either a reference type or a Nullable type. Parameter name: parameters

here is the controller code...

    //
    // GET: /Account/LogOn
    [RequiresSSL]
    public ActionResult LogOn(string ReturnUrl)
    {
        if (TempData["Message"] != null)
            ViewData["Message"] = TempData["Message"];

        TempData["Message"] = null;

        ViewData["ReturnUrl"] = ReturnUrl ?? "/Home"; 

        return View();
    }

Again, the RequireSSL Attribute works, but the POST from that SSL uri does not. What is not working?

Here is the Action (POST) Method, I apologize for not posting. This all works file when not running as SSL, but when i change to run under SSL the POST's do not work anymore.

    //
    // POST: /Account/LogOn
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult LogOn(string userName, string password, bool rememberMe, string returnUrl)
    {
        Logger.InfoFormat("LogOn : ({0}, PASSWORD, {1}, {2}).", userName, rememberMe, returnUrl);
        if (!ValidateLogOn(userName, password))
        {
            return View();
        }

        _FormsAuthentication.SignIn(userName, rememberMe);

        if (!String.IsNullOrEmpty(returnUrl))
        {
            return Redirect(this.Request.Url.AbsoluteUri.Replace(this.Request.RawUrl, returnUrl).Replace("https://", "http://"));
        }
        else
        {
            return Redirect(this.Request.Url.AbsoluteUri.Replace(this.Request.RawUrl, "/Home").Replace("https://", "http://"));
            //return RedirectToAction("Index", "Home");
        }
    }

Form HTML

                        <% using (Html.BeginLogOnForm()){ %>
                            <div class="logon-row logon-sso-row">
                                <div class="logon-links-row"><a href="<%=Url.Action("SingleSignOn", "Account", new{ReturnUrl=ViewData["ReturnUrl"]}) %>">Single Sign On</a></div>
                            </div>
                            <div class="logon-row">
                                <span class="block-span logon-label-cell">User Name:</span>
                                <span class="block-span"><%= Html.TextBox("username", null, new { style = "width:150px" })%></span>
                            </div>
                            <div class="logon-row">
                                <span class="block-span logon-label-cell">Password:</span>
                                <span class="block-span"><%= Html.Password("password", null, new { style="width:150px" })%></span>
                            </div>
                            <div class="logon-row">
                                <span class="block-span logon-label-cell">Remember Me?:</span>
                                <span class="block-span"><%= Html.CheckBox("rememberMe")%></span>
                            </div>
                            <div class="logon-row logon-bottons-row">
                                <input type="submit" value="Log On" class="mainshipButton mainshipPageButton" />
                            </div>
                            <div class="logon-row">
                                <div class="logon-links-row"><a href="<%=Url.Action("Request", "Account") %>">Request Account</a></div>
                                <div class="logon-links-row"><a href="<%=Url.Action("Forgot", "Account") %>">Forgot ID/Password</a></div>
                            </div>
                        <% } %>
A: 

It sounds like the model binder is trying to bind to a non nullable type in an action method. The action method you have listed does not have that type (rememberMe). Your routes may not be going where you think they are. Do you have an action method in one of your controllers that has the rememberMe parameter as a bool?

EDIT (After additional info added to question):

If a checkbox is not checked it will not return a value. It will be null. You need to add a hidden value above the checkbox with the same name like this:

<input type="hidden" name="rememberMe" value="false" />

Or use a nullable type bool?.

Matt Spradley
Ive updated the question above, i do have an action method for the post that does have that param. This all works fine when not running in SSL, once SSL is "required" the POST no longer works.
RyanFetz
Are you sure the rememberMe variable is in the form collection? You can inspect the Request.From collection to make sure the variable is there. I have not experienced any issues like you report with SSL connections.
Matt Spradley
Since it works fine when not using the HTTPS protocol i would say it seems to be an SSL issue but here is the form html.. as you can see the rememberMe param is mapped to a checkbox. (will post an edit for the html)
RyanFetz
A: 

Well after googling for hours, I closed my browser (IE).. then tried through FF (which worked). so i reopened IE and tryed through it and it worked fine.... not sure what the issue was but it seems fine now

RyanFetz
Check it with the checkbox unchecked. My guess is it still won't work.
Matt Spradley
Done, and worked fine...
RyanFetz