1. WebApiConfig에서 Route 설정하기 

App_Start 에서 WebApiConfig 파일에서 아래의 소스와 같이 만들어주면 된다.

students라는 ApiController가 있는데 routeTemplate을 바꿀 수 있다.

1
2
3
4
5
   config.Routes.MapHttpRoute(
                name: "students",
                routeTemplate: "api/students/{userName}",
                defaults: new { controller = "students", userName = RouteParameter.Optional }
            );
cs


2. Method Route 설정하기

1
2
3
4
5
6
7
public class UserIdCheckController : ApiController
    {
 
        [Route("User/{id}")]
        public int GetIdCheck(string id)
        {
        }
cs

메서드 마다 강제로 주소를 바꿀 수 있다.

Posted by Hoya0415
,