[c#] 사용자가 “로그인”되었는지 확인하는 방법은 무엇입니까?

내 ASP.NET 응용 프로그램에서 아래 방법으로 양식 인증을 사용하고 있습니다.

FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, true);

사용자의 로그인 여부를 어떻게 확인합니까? 로그인 한 사용자의 사용자 이름을 어떻게 얻을 수 있습니까?



답변

나는 올바른 것을 찾았습니다. 아래에 있습니다.

bool val1 = System.Web.HttpContext.Current.User.Identity.IsAuthenticated

편집하다

이 편집에 대한 크레딧은 댓글에서 이것을 제안한 @Gianpiero Caretti 에게 있습니다.

bool val1 = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated


답변

가장 간단한 방법 :

if (Request.IsAuthenticated) ...


답변

if (User.Identity.IsAuthenticated)
{
    Page.Title = "Home page for " + User.Identity.Name;
}
else
{
    Page.Title = "Home page for guest user.";
}


답변

그들이 인증되었는지 확인하는 가장 쉬운 방법 Request.User.IsAuthenticated은 (메모리에서)


답변