[英]How to force authentication across the whole web site in asp.net core?
我在暫存中部署了一個 asp.net 核心網站。 我可以在不登錄的情況下訪問 web 站點中的頁面。如果用戶未通過身份驗證,我如何在整個網站上進行身份驗證。
我找到了解決方案。 我在 Startup > ConfigureServices 添加了這個
services.AddMvc(config =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
config.Filters.Add(new AuthorizeFilter(policy));
});
現在,如果用戶未通過身份驗證並嘗試訪問 web 站點上的任何頁面,他會自動重定向到登錄頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.