这发生在我的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);
}
}
获取操作确定,成功登录后转到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中进行设置?
答案 0 :(得分:0)
这是由于Home控制器上的Authorize属性与Azure应用程序设置的“授权”部分中的“打开”AD(Active Directory)相结合而引起的。基本上,因为我登录了Microsoft Live帐户,所以它被选为有效登录。但由于我的Live登录没有输入Roles表,因此被拒绝,因此被发送回登录页面。