Below code is really working for login and logout. But i am facing an issue,
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(x => { x.LoginPath = "/UserAccount"; x.ExpireTimeSpan = TimeSpan.FromMinutes(10); x.SlidingExpiration = true; }); var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build(); services.AddMvc(options => { options.Filters.Add(new AuthorizeFilter(policy)); });
He opened that purchase screen tab and placed an order it is successfully placed
Add [Authorize]
to the action which place an order.
Below is a demo, I add a link to aa action in Confidential.cshtml. If first tab user log out, the second tab user cannot go to the aa action.
HomeController:
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
[Authorize]
public IActionResult ConfidentialData()
{
return View();
}
[Authorize]
public IActionResult aa()
{
return Ok(3);
}
}
Confidential.cshtml:
@if (User.Identity.IsAuthenticated)
{
<table class="table table-bordered">
@foreach (var claim in User.Claims) {
<tr><td>@claim.Type</td><td>@claim.Value</td></tr>
}
</table>
<li><a asp-controller="Home" asp-action="aa">Home</a></li>
}
result:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.