Asp.net core 用户重新验证页.net核心
一个页面,要求已登录的用户再次确认其密码,以确保某些操作的安全性。一旦确认,它将回到他们最初提出的任何请求(行动)。我应该为此使用用户API吗?我怎样才能做到这一点Asp.net core 用户重新验证页.net核心,asp.net-core,.net-core,asp.net-core-mvc,Asp.net Core,.net Core,Asp.net Core Mvc,一个页面,要求已登录的用户再次确认其密码,以确保某些操作的安全性。一旦确认,它将回到他们最初提出的任何请求(行动)。我应该为此使用用户API吗?我怎样才能做到这一点 Public IActionResult IndexMethod() { //process request only if user was verified using that verification page. //It can take in parameters such as tokens if needed }
Public IActionResult IndexMethod()
{
//process request only if user was verified using that verification page.
//It can take in parameters such as tokens if needed
}
在我看来,如果你想确认他们的密码一次以上的安全目的对某些行动。我建议您可以尝试使用操作过滤器,而不是直接转到操作,您可以将以前的url存储到会话中 更多详细信息,您可以参考以下测试演示: 1.启用会话: 将以下代码添加到Startup.cs的ConfigureServices方法中:
services.AddSession();
将以下代码添加到配置方法中:
app.UseSession();
2.创建一个过滤器:
public class ConfirmActionFilter : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext context)
{
base.OnActionExecuted(context);
}
public override void OnActionExecuting(ActionExecutingContext context)
{
//We will store the user is comfirmed into session and check it at the filter
if (String.IsNullOrEmpty(context.HttpContext.Session.GetString("checked")))
{
//store the path into session route .
context.HttpContext.Session.SetString("route", context.HttpContext.Request.Path);
//redirect to the confrim controller action
context.Result = new RedirectToActionResult("Index", "Confirm", context.HttpContext.Request.RouteValues);
}
}
}
3.添加确认控制器:
public class ConfirmController : Controller
{
public IActionResult Index()
{
//You could get the path
HttpContext.Session.SetString("checked","true");
return View();
}
public IActionResult Checked() {
// redirect to the path user has accessed.
var re = HttpContext.Session.GetString("route");
return new RedirectResult(re);
}
}
过滤器使用:
[ConfirmActionFilter]
public class HomeController : Controller
结果:
如果用户先访问,您会发现它将转到确认方法