gpt4 book ai didi

c# - return View ("viewname") 不返回指定的 View

转载 作者:行者123 更新时间:2023-11-30 18:22:42 24 4
gpt4 key购买 nike

使用 SPA 模板 我正在尝试获取 Login POST 方法以返回 VerifyEmail 查看用户是否尚未验证其电子邮件。

调试时你可以看到 return View("VerifyEmail") 被调用,但是,我返回到“/”并且 VerifyEmail View 没有被调用返回。

我已验证该 View 位于正确的文件夹 Views > Account 中。

我应该寻找一些自动路由配置吗?为什么我的 View 没有被返回?

[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
}
}

我试图添加这个,但根本没有帮助:

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

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

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);
}

这可能是导致问题的原因吗?

最佳答案

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

关于c# - return View ("viewname") 不返回指定的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33634897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com