FormsAuthentication.RedirectFromLoginPage(userName, createPersistentCookie) 寫入加密 Cookie 並導向原請求頁。Context.User.Identity.IsAuthenticated 判斷是否通過驗證,未驗證導向登入頁。<authentication mode="Forms">
<forms loginUrl="Login.aspx" />
</authentication>
<authorization>
<deny users="?" /> <!-- 禁止匿名用戶 -->
</authorization>
<location path="NewUser.aspx">
<system.web>
<authorization>
<allow users="*" /> <!-- 允許所有人存取註冊頁 -->
</authorization>
</system.web>
</location>
deny users="?" 封鎖所有匿名請求。location 區段對特定頁面覆蓋授權規則(如註冊頁允許匿名)。此方案為 ASP.NET 經典表單認證授權模式,清晰分離驗證與授權關注點。