【发布时间】:2015-11-10 16:31:47
【问题描述】:
使用 SPA 模板,如果用户尚未验证他们的电子邮件,我正在尝试使用 Login POST 方法返回 VerifyEmail 视图。
在调试时,您可以看到 return View("VerifyEmail") 被调用,但是,我返回到“/”并且没有返回 VerifyEmail 视图。
我已验证视图位于正确的文件夹视图 > 帐户中。
我应该寻找一些自动路由配置吗?为什么我的视图没有返回?
[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);
}
这可能是导致问题的原因吗?
【问题讨论】:
-
你试过用
return RedirectToAction("VerifyEmail");代替吗? -
@Jonnus,是的,我遇到了同样的“错误”
-
VerifyEmail 视图位于何处?
-
@enki.dev 视图在 Views 下,在与 Controller 同名的文件夹下
-
@cFrozenDeath,尝试在
ValidateClientRedirectUri中注释代码,尽管不应该这样,因为return View("...");不会重定向,它会呈现视图。
标签: c# asp.net-mvc