WebProfile - 인증 기능 적용
.NET프로그래밍/ASP.NET 3.5 SP1 2009. 10. 23. 16:08 |
ASP.NET 제공 로그인 컨트롤들
Register.aspx : CreateUserWizard 컨트롤
Login.aspx : 로그인 컨트롤
Default.aspx :
LoginView
LoginStatus
HyperLink
- Web.config 파일에 가서
<!-- 인증방식 변경 -->
<roleManager enabled="true" />
<authentication mode="Forms"></authentication>
- 인증 기능 적용
Admin 폴더를 만들고 관리자만 들어갈 수 있도록..
나만 볼 수 있는 페이지 만들기
Page.User.Identity.Name : 유저 아이디를 담고 있음
웹페이지에 Admin폴더 추가하고 관리자만 볼 수 있는 페이지 삽입
위 그림에서 처럼 ASP.NEt 관리 도구에서 Admin폴더에 접근 가능한 사용자를 정해주면
그 폴더에 대한 web.config파일이 생긴다.
[Admin/Web.config]
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<authorization>
<!-- 현재 Admin 폴더는 '박상혁'만 허용 -->
<!-- Administrators 그룹(역할)은 허용 -->
<allow users="박상혁" roles="Administrators"/>
<!-- 나머지는 거부 -->
<deny users="*"/>
</authorization>
</system.web>
</configuration>
* Profile
회원가입 추가 정보 : Profile
아이디
암호
---
이름
주소
나이
쉽게 추가 정보를 추가 삭제 할 수 있다
주소 정보 저장하고 싶을 때
Web.config파일에 <profile><property><add>로 주소추가
<!-- 프로필 -->
<profile>
<properties>
<add name="Name"/>
<add name="Age" type="System.Int32"/>
<add name="Address" type="System.String"/>
</properties>
</profile>
[UserInfor.aspx.cs]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class UserInfor : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
txtName.Text = Profile.Name; // 이름 출력
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
// 이름 저장
Profile.Name = txtName.Text;
Profile.Age = Convert.ToInt32(txtAge.Text);
Profile.Address = txtAddress.Text;
}
}
ASPNETDB.MDF 파일에 인증/프로필 값 저장이 아닌,
내가 만든 DB에 저장하고 싶다면?
aspnet_regsql.exe 명령어 사용 :
2.우리가 직접 Users 테이블 설계... 직접 기능 구현
로그인 + 프로필 : 직접 만들어서 사용하더라..
* LoginView 컨트롤
- AnonymousTemplate : 로그인 하기 전 상태. 인증 전
- LoggedInTemplate : 로그인 후 상태. 인증 후
[Default.aspx]의 <div>태그 내에 작성한 코드
<asp:LoginView ID="LoginView1" runat="server">
<AnonymousTemplate>
<asp:LoginStatus ID="LoginStatus1" runat="server" />
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Register.aspx">회원가입</asp:HyperLink><br />
손님으로 접속중입니다.
</AnonymousTemplate>
<LoggedInTemplate>
<asp:LoginStatus ID="LoginStatus2" runat="server" />
<asp:LoginName ID="LoginName1" runat="server" />
</LoggedInTemplate>
</asp:LoginView>
'.NET프로그래밍 > ASP.NET 3.5 SP1' 카테고리의 다른 글
XML 웹 서비스 (0) | 2009.10.27 |
---|---|
WebUser - 초간단 회원 관리 (인증 및 허가) 기능 구현 (0) | 2009.10.25 |
WebStandardControl - Panel 컨트롤 / MultiViewLogin 컨트롤 / Wizard컨트롤 (0) | 2009.10.23 |
SqlHelper 클래스와 Enterprise Library(4.1) (0) | 2009.10.21 |
WebDeployment (배포) (0) | 2009.10.21 |