我遇到一个简单的表单POST问题。 这是我的模特。
namespace OrientalWave.Models
{
public class LoginModel
{
[Required]
[Display(Name = "Utente")]
public string username { get; set; }
[Required]
[Display(Name = "Password")]
[DataType(DataType.Password)]
public string password { get; set; }
}
}
这是GET和POST操作:
[AllowAnonymous]
public ActionResult Login()
{
return View();
}
[AllowAnonymous]
[HttpPost]
public async Task<ActionResult> Login(LoginModel loginModel, string returnUrl)
{
// Login Stuff
}
CSHTML页面
@model OrientalWave.Models.LoginModel
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="vg_cont cont_all reglog">
<div class="login_container">
<section id="loginForm">
@using (Html.BeginForm("Login", "AdminManager", new { returnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form_m", @role = "form" }))
{
<h3>Accedi</h3>
@Html.ValidationSummary(true, "", new { @class = "validation_error_summary" })
<div class="form_gr">
@Html.LabelFor(loginModel => loginModel.username, new { @class = "lb_t" })
@Html.ValidationMessageFor(loginModel => loginModel.username, "", new { @class = "validation_error" })
@Html.TextBoxFor(loginModel => loginModel.username, new { @class = "", autocomplete = "off" })
</div>
<div class="form_gr">
@Html.LabelFor(loginModel => loginModel.password, new { @class = "lb_t" })
@Html.ValidationMessageFor(loginModel => loginModel.password, "", new { @class = "validation_error" })
@Html.PasswordFor(loginModel => loginModel.password, new { @class = "" })
</div>
<div class="form_gr">
<input type="submit" value="Accedi" class="sub_btn" />
</div>
}
</section>
</div>
</div>
@section scripts {
@Scripts.Render("~/bundles/jqueryval")
}
在我调试的本地机器上运行完美,但是当我将此应用程序部署到服务器时,似乎模型绑定器失败并且LoginModel值为null。我还检查了Request.Form属性并且为空。 什么可能导致这个错误?
修改 不知道它是否是导入,但Web服务器使用IIS 8.5和Plesk。
编辑2: 这是来自Fiddler的RAW请求。
POST http://oriental-wave.com/Admin/Login HTTP/1.1
Host: oriental-wave.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://oriental-wave.com/Admin/Login
Cookie: __RequestVerificationToken=V91OXcGfPjYTa39FXGNtHRyfjxGDygvha3JG32otYbDyAGY_uPSWeggyCYD1v0wAZPU7T4ggCtBM_IvAvq16jbu7EGa_ieAtGoL9PNrFC2A1
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
Content-Length: 32
username=**user**&password=**pass**