ASP.NET MVC 5.2의 새로운 기능
이 항목에서는 ASP.NET MVC 5.2, Microsoft.AspNet.MVC 5.2.2 및 ASP.NET MVC 5.2.3 베타의 새로운 사항에 대해 설명합니다.
소프트웨어 요구 사항
- Visual Studio 2012: Visual Studio 2012용 ASP.NET 및 Web Tools 2013.1을 다운로드합니다.
- Visual Studio 2013: Visual Studio 2013 업데이트 이상을 다운로드합니다. 이 업데이트는 MVC 5.2 Razor 뷰를 ASP.NET 편집하는 데 필요합니다.
다운로드
런타임 기능은 NuGet 갤러리에서 NuGet 패키지로 릴리스됩니다. 모든 런타임 패키지는 의미 체계 버전 관리 사양을 따릅니다. 최신 ASP.NET MVC 5.2 패키지에는 "5.2.0" 버전이 있습니다. NuGet을 통해 이러한 패키지를 설치하거나 업데이트할 수 있습니다. 릴리스에는 NuGet의 해당 지역화된 패키지도 포함되어 있습니다.
NuGet 패키지 관리자 콘솔을 사용하여 릴리스된 NuGet 패키지를 설치하거나 업데이트할 수 있습니다.
Install-Package Microsoft.AspNet.Mvc -Version 5.2.0
설명서
ASP.NET MVC 5.2에 대한 자습서 및 기타 정보는 ASP.NET 웹 사이트(https://www.asp.net/mvc)에서 확인할 수 있습니다.
ASP.NET MVC 5.2의 새로운 기능
특성 라우팅 개선 사항
특성 라우팅은 이제 IDirectRouteProvider라는 확장성 지점을 제공하므로 특성 경로가 검색 및 구성되는 방식을 완전히 제어할 수 있습니다. IDirectRouteProvider는 관련 경로 정보와 함께 작업 및 컨트롤러 목록을 제공하여 해당 작업에 필요한 라우팅 구성을 정확히 지정합니다. MapAttributes/MapHttpAttributeRoutes를 호출할 때 IDirectRouteProvider 구현을 지정할 수 있습니다.
기본 구현인 DefaultDirectRouteProvider를 확장하면 IDirectRouteProvider를 사용자 지정하는 것이 가장 쉽습니다. 이 클래스는 특성을 검색하고, 경로 항목을 만들고, 경로 접두사 및 영역 접두사를 검색하기 위한 논리를 변경하는 별도의 재정의 가능한 가상 메서드를 제공합니다.
IDirectRouteProvider의 새 특성 라우팅 확장성을 사용하여 사용자는 다음을 수행할 수 있습니다.
특성 경로의 상속을 지원합니다. 예를 들어 다음 시나리오에서 블로그 및 스토어 컨트롤러는 BaseController에 의해 정의된 특성 경로 규칙을 사용합니다.
[InheritedRoute("attributerouting/{controller}/{action=Index}/{id?}")] public abstract class BaseController : Controller { } public class BlogController : BaseController { public string Index() { return "Hello from blog!"; } } public class StoreController : BaseController { public string Index() { return "Hello from store!"; } } [AttributeUsage(AttributeTargets.Class, Inherited=true, AllowMultiple=true)] public class InheritedRouteAttribute : Attribute, IDirectRouteFactory { public InheritedRouteAttribute(string template) { Template=template; } public string Name { get; set; } public int Order { get; set; } public string Template { get; private set; } public new RouteEntry CreateRoute(DirectRouteFactoryContext context) { // context.Actions will always contain at least one action - and all of the // actions will always belong to the same controller. var controllerDescriptor=context.Actions.First().ControllerDescriptor; var template=Template.Replace("{controller}", controllerDescriptor.ControllerName); IDirectRouteBuilder builder=context.CreateBuilder(template); builder.Name=Name; builder.Order=Order; return builder.Build(); } } // Custom direct route provider which looks for route attributes of type // InheritedRouteAttribute and also supports attribute route inheritance. public class InheritedDirectRouteProvider : DefaultDirectRouteProvider { protected override IReadOnlyList<IDirectRouteFactory> GetControllerRouteFactories(ControllerDescriptor controllerDescriptor) { return controllerDescriptor .GetCustomAttributes(typeof(InheritedRouteAttribute), inherit: true) .Cast<IDirectRouteFactory>() .ToArray(); } }
특성 경로에 대한 경로 이름을 자동으로 생성합니다.
protected override IReadOnlyList<IDirectRouteFactory> GetActionRouteFactories(ActionDescriptor actionDescriptor) { // Get all the route attributes decorated directly on the actions IReadOnlyList<IDirectRouteFactory> actionRouteFactories=base.GetActionRouteFactories(actionDescriptor); // Check if the route attribute on each action already has a route name and if no, // generate a route name automatically // based on the convention: <ControllerName>_<ActionName> (ex: Customers_GetById) foreach (IDirectRouteFactory routeFactory in actionRouteFactories) { RouteAttribute routeAttr=routeFactory as RouteAttribute; if (string.IsNullOrEmpty(routeAttr.Name)) { routeAttr.Name=actionDescriptor.ControllerDescriptor.ControllerName + "_" + actionDescriptor.ActionName; } } return actionRouteFactories; } protected override IReadOnlyList<IDirectRouteFactory> GetControllerRouteFactories(ControllerDescriptor controllerDescriptor) { // Get all the route attributes decorated directly on the controllers IReadOnlyList<IDirectRouteFactory> controllerRouteFactories=base.GetControllerRouteFactories(controllerDescriptor); // Check if the route attribute on each controller already has a route name and if no, // generate a route name automatically // based on the convention: <ControllerName>Route (ex: CustomersRoute) foreach (IDirectRouteFactory routeFactory in controllerRouteFactories) { RouteAttribute routeAttr=routeFactory as RouteAttribute; if (string.IsNullOrEmpty(routeAttr.Name)) { routeAttr.Name=controllerDescriptor.ControllerName + "Route"; } } return controllerRouteFactories; }
경로가 경로 테이블에 추가되기 전에 한 중앙 위치에서 경로 접두사를 수정합니다.
특성 라우팅을 찾으려는 컨트롤러를 필터링합니다. 곧 3, 4에 블로그를 진행하겠습니다.
변경된 API 화면에 대한 Facebook 수정
MVC Facebook 패키지는 Facebook 몇 가지 API 변경으로 인해 중단되었습니다. 또한 이러한 문제를 해결하기 위해 새 Facebook 패키지(Microsoft.AspNet.Facebook 1.0.0)를 릴리스합니다.
알려진 문제 및 호환성이 손상되는 변경
MVC/Web API를 5.2.0 패키지가 있는 프로젝트로 스캐폴딩하면 프로젝트에 아직 없는 패키지에 대해 5.1.2 패키지가 생성됩니다.
ASP.NET MVC 5.2.0용 NuGet 패키지를 업데이트해도 ASP.NET 스캐폴딩 또는 ASP.NET 웹 애플리케이션 프로젝트 템플릿과 같은 Visual Studio 도구는 업데이트되지 않습니다. 이전 버전의 ASP.NET 런타임 패키지(예: 업데이트 2의 5.1.2)를 사용합니다. 따라서 ASP.NET 스캐폴딩은 프로젝트에서 아직 사용할 수 없는 경우 필요한 패키지의 이전 버전(예: 업데이트 2의 5.1.2)을 설치합니다. 그러나 Visual Studio 2013 RTM 또는 업데이트 1의 ASP.NET 스캐폴딩은 프로젝트의 최신 패키지를 덮어쓰지 않습니다. 프로젝트의 패키지를 Web API 2.2 또는 ASP.NET MVC 5.2로 업데이트한 후 ASP.NET 스캐폴딩을 사용하는 경우 Web API 및 ASP.NET MVC의 버전이 일관된지 확인합니다.
jQuery 1.4.1과 호환되는 Microsoft.jQuery.Unobtrusive.Validation 버전을 찾을 수 없으므로 Microsoft.jQuery.Unobtrusive.Validation NuGet 패키지 설치가 실패합니다.
Microsoft.jQuery.Unobtrusive.Validation에는 jQuery >=1.8 및 jQuery.Validation >=1.8이 필요합니다. 그러나 jQuery.Validation(1.8)에는 jQuery(≥ 1.3.2 && ≤ 1.6)가 필요합니다. 이 때문에 NuGet이 JQuery 1.8 및 jQuery.Validation 1.8을 동시에 설치하면 실패합니다. 이 문제가 표시되면 jQuery.Validation >버전을 먼저 jQuery 상한이 수정된 = 1.8.0.1 로 업데이트하면 Microsoft.jQuery.Unobtrusive.Validation을 설치할 수 있습니다.
jquery입니다. 유효성 검사 nuget 패키지 버전 1.13.0은 일부 국제 전자 메일 주소를 인식하지 못합니다.
jQuery.Validation nuget 패키지 버전 1.11.1은 다음 유효한 이메일 주소를 인식하는 마지막으로 알려진 버전입니다. 이후 버전에서는 이를 인식하지 못할 수 있습니다. 예를 들면 다음과 같습니다.
EAI(전자 메일 주소 국제화) 표준(예: 用户@domain.com)
EAI + IRI(Internationalized Resource Identifiers)(예: 用户@домен.р)
이 문제는 에서 보고됩니다. https://github.com/jzaefferer/jquery-validation/issues/1222
Visual Studio 2013 Razor 뷰에 대한 구문 강조 표시
Visual Studio 2013 업데이트하지 않고 ASP.NET MVC 5.2로 업데이트하는 경우 Razor 보기를 편집하는 동안 구문 강조 표시에 대한 Visual Studio 편집기 지원이 제공되지 않습니다. 이 지원을 받으려면 Visual Studio 2013 업데이트해야 합니다.