반응형
사용자가 "로그인"되었는지 확인하는 방법은 무엇입니까?
내 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) ...
그들이 인증되었는지 확인하는 가장 쉬운 방법 Request.User.IsAuthenticated
은 (메모리에서)
if (User.Identity.IsAuthenticated)
{
Page.Title = "Home page for " + User.Identity.Name;
}
else
{
Page.Title = "Home page for guest user.";
}
참고 URL : https://stackoverflow.com/questions/6086529/how-to-check-user-is-logged-in
반응형
'development' 카테고리의 다른 글
MySQL "Ca n't reopen table"오류 해결 (0) | 2020.09.24 |
---|---|
const에 대한 포인터 삭제 (T const *) (0) | 2020.09.24 |
blueimp 파일 업로드 플러그인의 maxFileSize 및 acceptFileTypes가 작동하지 않습니다. (0) | 2020.09.23 |
이러한 파일을로드 할 수 없습니다 — sqlite3 / sqlite3_native (LoadError) on ruby on rails (0) | 2020.09.23 |
사용자 정의 std :: set 비교기 사용 (0) | 2020.09.23 |