【发布时间】:2016-07-08 15:02:54
【问题描述】:
我的控制器操作之一拒绝进行身份验证,我不明白为什么。它只是 Visual Studio 中标准 MVC 5 项目模板中的标准 VerifyCode 操作,它看起来像这样:
[AllowAnonymous]
public async Task<ActionResult> VerifyCode(string provider, string returnUrl, bool rememberMe)
{
if (!await SignInManager.HasBeenVerifiedAsync())
{
return View("Error");
}
return View(new VerifyCodeViewModel { Provider = provider, ReturnUrl = returnUrl, RememberMe = rememberMe });
}
每当我的应用程序在没有用户登录的情况下点击此控制器时,它会将用户返回到登录屏幕,即使它已被 AllowAnonymous 修饰。相比之下,这个标准的控制器动作:
[AllowAnonymous]
public ActionResult ForgotPassword()
{
return View();
}
如果没有登录用户直接点击,效果很好。
为了弄清楚发生了什么,我在控制器中添加了以下测试操作:
// to see if it's down to the parameters
[AllowAnonymous]
public ActionResult VerifyCode()
{
return View(new VerifyCodeViewModel { Provider = "", ReturnUrl = "", RememberMe = false });
}
// to see if it's down to the action name
[AllowAnonymous]
public ActionResult VerifyCod()
{
return View(new VerifyCodeViewModel { Provider = "", ReturnUrl = "", RememberMe = false });
}
// to see if it's down to the viewmodel
[AllowAnonymous]
public ActionResult ForgotPassword()
{
return View(new VerifyCodeViewModel { Provider = "", ReturnUrl = "", RememberMe = false });
}
点击其中的前两个会导致我的应用程序将我发送回登录页面。点击第三个可以毫无问题地呈现 ForgotPassword 视图。
我没有任何自定义授权过滤器。这里到底发生了什么?
【问题讨论】:
标签: c# asp.net asp.net-mvc authentication owin