【发布时间】:2015-08-11 11:30:14
【问题描述】:
这发生在我的 MVC 项目的登录屏幕上,控制器代码如下:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
var result = await SignInManager.PasswordSignInAsync(model.UserId, model.Password, model.RememberMe, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToAction("Index", "Home"); <-- Gets here OK
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
default:
ModelState.AddModelError("", "Login details were incorrect.");
return View(model);
}
}
Get 进入操作 OK,成功登录后进入 RedirectToAction,但随后返回登录屏幕。
如果我通过 localhost 在本地运行它,它工作正常,在 Home Controller 上的 Index 操作上命中断点。从 Azure 调试时,它不会。
登录视图是:
@using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" })) {
@Html.AntiForgeryToken()
<h3 class="form-title">Sign In to your Account</h3>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
<!--@Html.LabelFor(m => m.UserId, new {@class = "col-md-2 control-label"})-->
<div class="input-icon">
<i class="icon-user"></i>
@Html.TextBoxFor(m => m.UserId, new { @class = "form-control", @placeholder = "Username" })
@Html.ValidationMessageFor(m => m.UserId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<!--@Html.LabelFor(m => m.Password, new {@class = "col-md-2 control-label"})-->
<div class="input-icon">
<i class="icon-lock"></i>
@Html.PasswordFor(m => m.Password, new { @class = "form-control", @placeholder = "Password" })
@Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-actions">
<div class="checkbox pull-left">
@Html.CheckBoxFor(m => m.RememberMe, htmlAttributes: new { @class = "uniform checkbox" })
@Html.LabelFor(m => m.RememberMe, htmlAttributes: new { @class = "control-label" })
</div>
<button type="submit" class="submit btn btn-primary pull-right">
Sign In <i class="icon-angle-right"></i>
</button>
</div>
}
首页/索引是一个乏味的:
public ActionResult Index() {
return View();
}
不确定这是我的代码,还是需要在 Azure 中进行设置?
【问题讨论】:
-
你怎么知道它正在到达
RedirectToAction行? -
“附加调试器”在 Visual Studio 中已发布的 Azure 应用上。
-
Home 动作是什么样的,索引控制器上有什么属性?
-
我刚刚发现这是一个授权问题。控制器上有一个 [Authourize] 属性,将其删除并通过,okish。问题是它现在需要一个 Windows Live Id。
标签: asp.net-mvc azure