Notice
Recent Posts
Recent Comments
Tags
- javascript 바코드스캔
- javascript 유효성체크
- TempData
- XSS PHP
- 하드 윈도우 복사
- 맥 오라클설치
- asp.net Select
- jquery 바코드생성
- 말줄임표시
- ViewBag
- asp.net dropdownlist
- 바코드 생성하기
- XSS방어
- javascript 바코드 생성
- ViewData
- django 엑셀불러오기
- asp.net core Select
- jquery 바코드
- 파일업로드 유효성체크
- Mac Oracle
- 강제이동
- 타임피커
- javascript redirection
- ASP.Net Core 404
- SSD 복사
- 바코드 스캔하기
- 404에러페이지
- 하드 마이그레이션
- 파일업로드 체크
- php 캐쉬제거
웹개발자의 기지개
[ASP.Net Core] 라우팅 Custom 지정하기 (Route) 본문
ASP.NET/ASP.NET Core
[ASP.Net Core] 라우팅 Custom 지정하기 (Route)
http://portfolio.wonpaper.net 2023. 3. 6. 00:24Route 지정하는 방법이다.
크게 두가지로 나누어 볼수 있다.
1. Program.cs ( ASP.Net Core 3이하에서는 Startup.cs ) 내에서
app.UseEndpoints(endpoints) 지정하는 방법
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Main}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{controller=Main}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "Sports_Detail",
pattern: "Sports/Detail/{pgid?}/{moncnt=1}",
defaults: new {controller="Sports", action="Detail"}
);
endpoints.MapControllerRoute(
name: "FileDown",
pattern: "Notice/FileDown/{id?}/{num=1}",
defaults: new {controller="Notice", action= "FileDown" }
);
});
app.Run();
|
cs |
위의 소스를 보면
4 라인은 기본적으로 컨트롤/액션메소드/id값으로 지정하는데, 이때 controller을 안쓰면 기본값이 Main 이고, 액션메소드도 마찬가지로 없다면 기본이 Index 이다. 그리고, id값은 없어도 되는데 있다면 지정해도 된는데 이때는 string id 파라이터 값을 그대로 연결해 준다.
10라인과 15라인은 임의지정하는 Route 인데,각각 Sports 와 Detail 컨트롤러와 액션메소드로 고정으로 지정하는 방식이다.
2. 액션메소드 상단에 Route Annotation 지정하는 방법
컨트롤러의 각각의 액션메도스 상단에 아래와 같이 직접 지정해도 되겠다.
1
2
3
4
5
6
7
8
9
10
|
public class ExhibitorsController:Controller
[Route("~/Exhibitors/{eventId}/{companyId}")]
public IActionResult Index (int eventId, int companyId)
public class DemoQueueController:Controller
[Route("~/DemoQueue/{eventId}/{companyId}")]
public IActionResult Index (int eventId, int companyId)
|
cs |
참고 : https://stackoverflow.com/questions/64434079/setting-up-routes-in-asp-net-core-3-mvc-web-app
'ASP.NET > ASP.NET Core' 카테고리의 다른 글
Comments