【问题标题】:RedirectToAction does not work in AzureRedirectToAction 在 Azure 中不起作用
【发布时间】: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


【解决方案1】:

这是由 Home 控制器上的 Authorize 属性与 Azure 应用程序设置的 Authorization 部分中的 AD (Active Directory) 为“开”引起的。本质上,因为我登录了 Microsoft Live 帐户,所以它被认为是有效的登录名。但由于我的 Live 登录未输入到 Roles 表中,因此被拒绝,因此被发送回登录页面。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-06
    • 1970-01-01
    • 2014-04-19
    相关资源
    最近更新 更多