MVC3 - Form + POST =空参数

时间:2011-06-20 08:15:42

标签: apache forms asp.net-mvc-3 mono controller

我目前正在开发一个ASP.NET MVC3网站。

我有一个简单的身份验证表单,绑定在一个简单的viewmodel上。在本地调试时,一切正常。

但该网站也必须使用Apache + monomod。这是我遇到的奇怪行为:具有相同请求和参数的相同形式无法正常工作。

更多详情:

viewmodel:

/// <summary>
/// Form authentication info
/// </summary>
public class LogOnModel
{
    /// <summary>
    /// 
    /// </summary>
    [DisplayName("Username")]
    public string UserName { get; set; }

    /// <summary>
    /// 
    /// </summary>
    [DisplayName("Password")]
    public string Password { get; set; }

    /// <summary>
    /// 
    /// </summary>
    [DisplayName("Remember me?")]
    public bool RememberMe { get; set; }

    /// <summary>
    /// Targeted URL
    /// </summary>
    public string Target { get; set; }

    /// <summary>
    /// 
    /// </summary>
    public LogOnModel()
    {
    }
}

/// <summary> /// Form authentication info /// </summary> public class LogOnModel { /// <summary> /// /// </summary> [DisplayName("Username")] public string UserName { get; set; } /// <summary> /// /// </summary> [DisplayName("Password")] public string Password { get; set; } /// <summary> /// /// </summary> [DisplayName("Remember me?")] public bool RememberMe { get; set; } /// <summary> /// Targeted URL /// </summary> public string Target { get; set; } /// <summary> /// /// </summary> public LogOnModel() { } }

视图的主要部分,用户可以在其中输入用户名和密码的页面:

<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<Website.Areas.Public.Models.LogOnModel>" %>
<p>
    Please enter your username and password to continue.
</p>
<% using (Html.BeginForm())
   { %>
<%= Html.ValidationSummary(true, "Authentication failed.")%>
<p>
    <%= Html.ActionLink("I forgot my password","PasswordRecovery","Home") %>
</p>
<div>
    <fieldset>
        <div class="editor-label">
            <%= Html.LabelFor(m => m.UserName) %>
        </div>
        <div class="editor-field">
            <%= Html.TextBoxFor(m => m.UserName) %>
            <%= Html.ValidationMessageFor(m => m.UserName)%>
        </div>
        <div class="editor-label">
            <%= Html.LabelFor(m => m.Password)%>
        </div>
        <div class="editor-field">
            <%= Html.PasswordFor(m => m.Password) %>
            <%= Html.ValidationMessageFor(m => m.Password) %>
        </div>
        <div class="editor-field">
            <%= Html.CheckBoxFor(m => m.RememberMe) %>
            Remember me
        </div>
        <p>
            <input type="submit" value="Connect me!" />
        </p>
    </fieldset>
</div>
<% } %>

控制器,接收auth信息:

<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<Website.Areas.Public.Models.LogOnModel>" %> <p> Please enter your username and password to continue. </p> <% using (Html.BeginForm()) { %> <%= Html.ValidationSummary(true, "Authentication failed.")%> <p> <%= Html.ActionLink("I forgot my password","PasswordRecovery","Home") %> </p> <div> <fieldset> <div class="editor-label"> <%= Html.LabelFor(m => m.UserName) %> </div> <div class="editor-field"> <%= Html.TextBoxFor(m => m.UserName) %> <%= Html.ValidationMessageFor(m => m.UserName)%> </div> <div class="editor-label"> <%= Html.LabelFor(m => m.Password)%> </div> <div class="editor-field"> <%= Html.PasswordFor(m => m.Password) %> <%= Html.ValidationMessageFor(m => m.Password) %> </div> <div class="editor-field"> <%= Html.CheckBoxFor(m => m.RememberMe) %> Remember me </div> <p> <input type="submit" value="Connect me!" /> </p> </fieldset> </div> <% } %>

正如我在评论中所说,用户名&amp;密码是空的。在本地ASP.NET调试服务器上一切正常,并且使用Fiddler我可以看到身份验证请求包含表单数据(用户名,密码等)。

知道为什么绑定似乎不起作用? 感谢。

2 个答案:

答案 0 :(得分:0)

您使用的是什么版本的单声道?当我第一次尝试在单声道(2.4或2.6)上设置MVC 2站点时遇到了这个问题。我不记得底层原因是什么,因为它已经修复了相当复杂的单声道/实现差异 - 运行在单声道2.10.2上的MVC3 / Razor按预期工作。

答案 1 :(得分:0)

几个月后,我找到了答案。这有点晚了但是如果有人有同样的问题,这就是解决方案:

清理Web.config文件。删除所有选项

的行