使用 AllowAnonymous 與 Authorize 在 Class Level 差異
在 Class 上設定 AllowAnonymous 屬性,跟設定 Authorize 效果相同嗎?
以下說明
[AllowAnonymous] 在 Class Level
1 | [] |
雖然 Method Secure 設定 [Authorize],但它會被 Class 的 [AllowAnonymous],
所以 Secure Method 還是允許匿名訪問。
[Authorize] 在 Class Level
1 | [] |
整個 Class 設定為 [Authorize],除了 Public Method 設定 [AllowAnonymous] 會覆寫 [Authorize],所以允許匿名訪問。
詳細請參考 ASP0026:[AllowAnonymous] 從「更遠」覆寫 [Authorize]
所以在使用 [AllowAnonymous] 時,要小心哦~