开发者

ASP.NET MVC SSL POST Error

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 = "wi开发者_如何转开发dth: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>
                        <% } %>


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


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?.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜