RouteTable
에 Routes
의 URL을 열거하는 방법을 알아 내려고하고 있습니다. 내 사이트가 mysite.com, mysite.com/create이 PadController.CreateNote()
호출하는 경우, 즉ASP.NET MVC RouteTable 경로 URL 열거
routes.MapRoute
("PadCreateNote", "create", new { controller = "Pad", action = "CreateNote" });
routes.MapRoute
("PadDeleteNote", "delete", new { controller = "Pad", action = "DeleteNote" });
routes.MapRoute
("PadUserIndex", "{username}", new { controller = "Pad", action = "Index" });
및 mysite.com/foobaris는 PadController.Index()
를 호출 내 시나리오에서
는, 나는 다음과 같은 노선 정의 .
가 나는 또한 클래스 강하게 유형의 사용자 이름이 있습니다
public class Username
{
public readonly string value;
public Username(string name)
{
if (String.IsNullOrWhiteSpace(name))
{
throw new ArgumentException
("Is null or contains only whitespace.", "name");
}
//... make sure 'name' isn't a route URL off root like 'create', 'delete'
this.value = name.Trim();
}
public override string ToString()
{
return this.value;
}
}
Username
의 생성자에서를, 나는 name
정의 된 경로가 아닌지 확인 확인하고 싶습니다. 예를 들어 다음과 같은 경우 :
var username = new Username("create");
예외가 발생해야합니다. //... make sure 'name' isn't a route URL off root
을 (를) 대체하려면 무엇이 필요합니까?
주어진 경로의 DataTokens에 'protected'부울을 추가하는 것은 무리가되지 않습니다. 필연적으로 제안하는 것은 아니지만 관리가 특히 어렵지는 않습니다. –