返回View("viewname"),不返回指定的视图 [英] return View("viewname") not returning the view specified

查看:40
本文介绍了返回View("viewname"),不返回指定的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用SPA模板,我尝试获取 Login POST方法以返回 VerifyEmail 视图(如果用户尚未验证其电子邮件).

Using the SPA Template I'm trying to get the Login POST method to return the VerifyEmail View if the user has not verified their email yet.

在调试时,您可以看到正在调用 return View("VerifyEmail"),但是,我返回到了"/",而没有在 VerifyEmail 视图中返回.

While debugging you can see the return View("VerifyEmail") being called, however, I'm returned to "/" and the VerifyEmail view is not being returned.

我已确认该视图位于正确的文件夹视图>帐户"中.

I have verified that the View is in the correct folder Views > Account.

我应该寻找一些自动路由配置吗?为什么不返回我的视图?

Is there some automatic routing configuration I should look for? Why isn't my View being returned?

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> LogOn(LogOnVM model, string returnUrl)
{
    if (!ModelState.IsValid)
        return View(model);

    switch (await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, true))
    {
        case SignInStatus.Success:
            MyUser user = await UserManager.FindByNameAsync(model.UserName);
            if (!await UserManager.IsEmailConfirmedAsync(user.UserName))
                return View("VerifyEmail");
            else
                return RedirectToLocal(returnUrl);
        //other cases ignored for brevity
    }
}

我尝试添加它,但是根本没有帮助:

I tried to add this, but didn't help at all:

public ActionResult VerifyEmail()
{
    return View();
}

我正在搜索并在我的代码中找到了这个,显然是因为默认模板:

I was searching and found this in my code, obviously there because of the default template:

public override Task ValidateClientRedirectUri(OAuthValidateClientRedirectUriContext context)
{
    if (context == null)
        throw new ArgumentNullException("context");

    if (context.ClientId == _publicClientId)
    {
        Uri expectedRootUri = new Uri(context.Request.Uri, "/");

        if (expectedRootUri.AbsoluteUri == context.RedirectUri)
        {
            context.Validated();
        }
        else if (context.ClientId == "web")
        {
            var expectedUri = new Uri(context.Request.Uri, "/");
            context.Validated(expectedUri.AbsoluteUri);
        }
    }
    return Task.FromResult<object>(null);
}

这是引起问题的原因吗?

Could this be what's causing the problem?

推荐答案

注释我上次编辑的代码无效,但我发现从/account/logon中删除?ReturnUrl =%2F ?ReturnUrl =%2F可以解决问题.ReturnUrl在登录视图的 @ Html.BeginForm 下作为 routeValues 传递.我想我只是将 null 传递给 routeValues 即可解决问题!

Commenting the code in my last edit did not work, but I see that removing ?ReturnUrl=%2F from /account/logon?ReturnUrl=%2F does the trick. The ReturnUrl is passed as routeValues under @Html.BeginForm for the LogOn View. I figured I'd just pass null to routeValues which fixed the issue!

这篇关于返回View("viewname"),不返回指定的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆