라우팅
- 일반적으로 Global.asax 파일의 Application_Start 이벤트 처리기에서 호출되는 메서드에서 경로를 추가합니다.
- 응용 프로그램이 시작될 때 경로를 사용할 수 있게 됩니다.
1 2 3 4 5 6 7 8 9 | protected void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); } public static void RegisterRoutes(RouteCollection routes) { routes.Add(); } | cs |
예제
1 2 3 4 5 6 7 8 | routes.MapPageRoute("라우트네임", "라우트url", "물리적url", false, new RouteValueDictionary { { "index", "초기값" } }, new RouteValueDictionary { { "index", @"제약조건 정규식" } } ); | cs |
MapPageRoute 정적메서드 파라미터 분석
1. 라우트네임 : 라우트에서 구분하기 위한 특별한 이름, 유니크하게 설정
2. 라우트url : 내가 원하는 url
3. 물리적url : 기존 url
4. RouteValueDictionary 클래스를 이용하여 초기값과 제약조건을 설정
실제 사용된 예제
1 2 3 4 | routes.MapPageRoute("Notification", "notification/{index}", "~/news/noti.aspx", false, new RouteValueDictionary { { "index", 0 } }, new RouteValueDictionary { { "index", @"^\d{1,9}$" } } ); | cs |
2. 도메인/notification/index url 사용, index에는 해당 페이지 키값이 들어간다.
3. 물리적인 기존 url
4. 초기값은 0으로 들어가고, 제약조건 정규식에는 숫자 1자리이상 9자리 이하까지라는 조건 포함.
Web.config
1 2 3 | <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> | cs |
Web.config에 해당 내용이 존재해야 한다.
'개발 > ASP.NET' 카테고리의 다른 글
현재/이전 페이지 주소 (0) | 2018.03.09 |
---|---|
ClientScriptManager (0) | 2018.03.08 |
linq class 내에 포함된 속성만 array로 리턴 (0) | 2018.01.24 |
업로드 파일 용량 제어하기 (0) | 2017.09.21 |
gridView repeater 리스트 갯수 0개일때 (0) | 2017.09.01 |