2011. 9. 16. 13:44

사용자 인증


인증 과정
FormsAuthentication 클래스는 사용자 인증을 하는데 필요한 기본 클래스 입니다. 이 클래스는 Security 네임스페이스에 포함되어 있습니다.

using System.Web.Security;


-> 사용자가 웹 애플리케이션에 있는 페이지를 요구합니다.
-> 인증된 사용자인지 검사하고, 아니면 로그인페이지로 이동시켜 사용자 인증을 받습니다.
-> 로그인 페이지에서 사용자로부터 아이디와 암호를 입력받아 권한이 있는 사용자인지 검사합니다.
    (FormsAuthentication.Authenticate 메서드 또는 사용자 데이터 베이스 이용).
-> 인증된 사용자는 인증 정보를 쿠키로 저장하고, 사용자가 원래 요구했던 페이지로 이동시켜줍니다.
    (FormsAuthentication.GetRedriectUrl 메서드)    




* 일반적으로 사용자 인증 방식은 아래 그림과 같습니다.<참조 : http://man.ddvip.com>




  1. The user issues a Web request for Default.aspx.

    IIS allows the request because Anonymous access is enabled. ASP.NET checks the <authorization> elements and finds a <deny users=?” /> element.

  2. The user is redirected to the login page (Login.aspx) as specified by the loginUrl attribute of the <forms> element.

  3. The user supplies credentials and submits the login form.

  4. The credentials are validated against a store (SQL Server or Active Directory) and roles are optionally retrieved. You must retrieve a role list if you want to use role-based authorization.

  5. A cookie is created with a FormsAuthenticationTicket and sent back to the client. Roles are optionally stored in the ticket. By storing the role list in the ticket, you avoid having to access the database to re-retrieve the list for each successive Web request from the same user.

  6. The user is redirected with client-side redirection to the originally requested page (Default.aspx).

  7. In the Application_AuthenticateRequest event handler (in Global.asax), the ticket is used to create an IPrincipal object and it is stored in HttpContext.User.

    ASP.NET checks the <authorization> elements and finds a <deny users=?” /> element. However, this time the user is authenticated.

    ASP.NET checks the <authorization> elements to ensure the user is in the <allow> element.

    The user is granted access to Default.aspx.