Nice programing

ASP.NET MVC 3과 4의 차이점은 무엇입니까?

nicepro 2020. 11. 24. 19:55
반응형

ASP.NET MVC 3과 4의 차이점은 무엇입니까?


MVC4의 모든 새로운 기능과 MVC3에서 변경된 사항을 모두 설명하는 포괄적 인 목록이 있습니까?

( 릴리스 노트 는별로 도움이되지 않습니다.)


MVC4 릴리스 노트 에서 복사 및 붙여 넣기 :

최신 HTTP 프로그래밍 모델 : 강력한 형식의 새 HTTP 개체 모델을 사용하여 웹 API에서 HTTP 요청 및 응답에 직접 액세스하고 조작합니다. 새로운 HttpClient 유형을 통해 클라이언트에서 동일한 프로그래밍 모델과 HTTP 파이프 라인을 대칭 적으로 사용할 수 있습니다.

경로에 대한 완벽한 지원 : ASP.NET Web API는 경로 매개 변수 및 제약 조건을 포함하여 ASP.NET 라우팅의 전체 경로 기능 집합을 지원합니다. 또한 간단한 규칙을 사용하여 작업을 HTTP 메서드에 매핑합니다.

콘텐츠 협상 : 클라이언트와 서버가 함께 작동하여 웹 API에서 반환되는 데이터에 적합한 형식을 결정할 수 있습니다. ASP.NET Web API는 XML, JSON 및 양식 URL 인코딩 형식에 대한 기본 지원을 제공하며 고유 한 포맷터를 추가하여이 지원을 확장하거나 기본 콘텐츠 협상 전략을 대체 할 수도 있습니다.

모델 바인딩 및 유효성 검사 : 모델 바인더는 HTTP 요청의 다양한 부분에서 데이터를 추출하고 이러한 메시지 부분을 Web API 작업에서 사용할 수있는 .NET 개체로 변환하는 쉬운 방법을 제공합니다. 데이터 주석을 기반으로 동작 매개 변수에 대해서도 유효성 검사가 수행됩니다.

필터 : ASP.NET Web API는 [Authorize] 속성과 같이 잘 알려진 필터를 포함한 필터를 지원합니다. 작업, 권한 부여 및 예외 처리를 위해 고유 한 필터를 작성하고 연결할 수 있습니다.

쿼리 구성 : IQueryable을 반환하는 작업에 [Queryable] 필터 속성을 사용하여 OData 쿼리 규칙을 통해 웹 API 쿼리를 지원할 수 있습니다.

향상된 테스트 가능성 : 정적 컨텍스트 개체에서 HTTP 세부 정보를 설정하는 대신 웹 API 작업은 HttpRequestMessage 및 HttpResponseMessage의 인스턴스와 함께 작동합니다. Web API 프로젝트와 함께 단위 테스트 프로젝트를 만들어 웹 API 기능에 대한 단위 테스트 작성을 빠르게 시작하세요.

코드 기반 구성 : ASP.NET Web API 구성은 코드를 통해서만 수행되므로 구성 파일은 깨끗하게 유지됩니다. 제공 서비스 로케이터 패턴을 사용하여 확장 지점을 구성합니다.

IoC (Inversion of Control) 컨테이너에 대한 지원 향상 : ASP.NET Web API는 향상된 종속성 확인자 추상화를 통해 IoC 컨테이너에 대한 뛰어난 지원을 제공합니다.

자체 호스트 : 웹 API의 경로 및 기타 기능의 전체 기능을 계속 사용하면서 IIS 외에도 자체 프로세스에서 웹 API를 호스팅 할 수 있습니다.

사용자 정의 도움말 및 테스트 페이지 생성 : 이제 새로운 IApiExplorer 서비스를 사용하여 웹 API에 대한 완전한 런타임 설명을 가져옴으로써 웹 API에 대한 사용자 정의 도움말 및 테스트 페이지를 쉽게 구축 할 수 있습니다.

모니터링 및 진단 : ASP.NET Web API는 이제 System.Diagnostics, ETW 및 타사 로깅 프레임 워크와 같은 기존 로깅 솔루션과 쉽게 통합 할 수있는 경량 추적 인프라를 제공합니다. ITraceWriter 구현을 제공하고 웹 API 구성에 추가하여 추적을 활성화 할 수 있습니다.

링크 생성 : ASP.NET Web API UrlHelper를 사용하여 동일한 응용 프로그램의 관련 리소스에 대한 링크를 생성합니다.

웹 API 프로젝트 템플릿 : 새 MVC 4 프로젝트 마법사에서 새 웹 API 프로젝트를 선택하여 ASP.NET 웹 API를 빠르게 시작하고 실행할 수 있습니다.

스캐 폴딩 : 컨트롤러 추가 대화 상자를 사용하여 Entity Framework 기반 모델 유형을 기반으로 웹 API 컨트롤러를 빠르게 스캐 폴드합니다.


MVC4의 새로운 기능-MVC3 Vs MVC4 에서 복사하여 붙여 넣기

MVC4의 새로운 기능-MVC3 대 MVC4

기본 프로젝트 템플릿 향상

새로운 ASP.NET MVC 4 프로젝트를 만드는 데 사용되는 템플릿이 업데이트되어보다 현대적인 웹 사이트를 만들 수 있습니다.

모바일 프로젝트 템플릿

새 프로젝트를 시작하고 모바일 및 태블릿 브라우저 용으로 특별히 사이트를 생성하려는 경우 새 모바일 애플리케이션 프로젝트 템플릿을 사용할 수 있습니다. 이는 터치에 최적화 된 UI를 구축하기위한 오픈 소스 라이브러리 인 jQuery Mobile을 기반으로합니다.

디스플레이 모드

새로운 디스플레이 모드 기능을 사용하면 애플리케이션이 요청을 보내는 브라우저에 따라보기를 선택할 수 있습니다. 예를 들어 데스크톱 브라우저가 홈 페이지를 요청하는 경우 애플리케이션은 Views\Home\Index.cshtml템플릿을 사용할 수 있습니다 . 모바일 브라우저가 홈 페이지를 요청하면 애플리케이션이 Views\Home\Index.mobile.cshtml템플릿을 반환 할 수 있습니다 .

DisplayModes.Modes.Insert(0, new DefaultDisplayMode("iPhone")
{
  ContextCondition = (context => context.Request.UserAgent.IndexOf
    ("iPhone", StringComparison.OrdinalIgnoreCase) >= 0)
});

jQuery Mobile,보기 전환기 및 브라우저 재정의

jQuery Mobile은 터치에 최적화 된 웹 UI를 구축하기위한 오픈 소스 라이브러리입니다. ASP.NET MVC 4 애플리케이션에서 jQuery Mobile을 사용하려는 경우 시작하는 데 도움이되는 NuGet 패키지를 다운로드하여 설치할 수 있습니다. Visual Studio 패키지 관리자 콘솔에서 설치하려면 다음 명령을 입력하십시오. Install-Package jQuery.Mobile.MVC 그러면 jQuery Mobile 및 다음을 포함한 일부 도우미 파일이 설치됩니다. Views / Shared / Layout.Mobile.cshtml, jQuery Mobile 기반 레이아웃. Views / Shared / ViewSwitcher.cshtml 부분보기 및 ViewSwitcherController.cs 컨트롤러로 구성된보기 전환기 구성 요소입니다. 패키지를 설치 한 후 모바일 브라우저 (또는 Firefox User Agent Switcher 애드온과 같은 동등한 기능)를 사용하여 애플리케이션을 실행하십시오. 페이지가 상당히 다르게 보이는 것을 볼 수 있습니다. jQuery Mobile이 레이아웃과 스타일을 처리하기 때문입니다. 이를 활용하기 위해 다음을 수행 할 수 있습니다. 방문자가 링크를 클릭하면 동일한 페이지의 데스크톱 버전으로 전환됩니다. 데스크톱 레이아웃에는 기본적으로보기 전환기가 포함되지 않기 때문에 방문자는 모바일 모드로 이동할 수 없습니다. 이를 활성화하려면 _ViewSwitcher에 대한 다음 참조를 요소 내부의 데스크톱 레이아웃에 추가합니다.

@Html.Partial("_ViewSwitcher")

... 브라우저 재정의는 ASP.NET MVC 4의 핵심 기능이며 jQuery.Mobile.MVC 패키지를 설치하지 않아도 사용할 수 있습니다. 그러나보기, 레이아웃 및 부분보기 선택에만 영향을 미치며 Request.Browser 개체에 의존하는 다른 ASP.NET 기능에는 영향을주지 않습니다.

Visual Studio에서 코드 생성을위한 레시피

새로운 레시피 기능을 사용하면 Visual Studio에서 NuGet을 사용하여 설치할 수있는 패키지를 기반으로 솔루션 별 코드를 생성 할 수 있습니다. Recipes 프레임 워크를 사용하면 개발자가 코드 생성 플러그인을 쉽게 작성할 수 있으며,이 플러그인을 사용하여 영역 추가, 컨트롤러 추가 및보기 추가에 대한 기본 제공 코드 생성기를 대체 할 수도 있습니다. 레시피는 NuGet 패키지로 배포되기 때문에 소스 제어에 쉽게 체크인하고 프로젝트의 모든 개발자와 자동으로 공유 할 수 있습니다. 솔루션별로도 제공됩니다.

비동기 컨트롤러에 대한 작업 지원

이제 비동기 작업 메서드를 Task 또는 Task 유형의 개체를 반환하는 단일 메서드로 작성할 수 있습니다.

예를 들어 Visual C # 5를 사용하거나 Async CTP를 사용하는 경우 다음과 같은 비동기 작업 메서드를 만들 수 있습니다.

public async Task Index(string city) {
    var newsService = new NewsService();
    var sportsService = new SportsService();

    return View("Common", new PortalViewModel {
      NewsHeadlines = await newsService.GetHeadlinesAsync(),
      SportsScores = await sportsService.GetScoresAsync()
    });
}

이전 작업 메서드에서 newsService.GetHeadlinesAsync 및 sportsService.GetScoresAsync에 대한 호출은 비동기 적으로 호출되며 스레드 풀에서 스레드를 차단하지 않습니다.

Task 인스턴스를 반환하는 비동기 작업 메서드도 시간 제한을 지원할 수 있습니다. 작업 메서드를 취소 할 수 있도록하려면 CancellationToken 유형의 매개 변수를 작업 메서드 서명에 추가합니다. 다음 예제는 제한 시간이 2500 밀리 초이고 제한 시간이 발생하는 경우 클라이언트에 TimedOut보기를 표시하는 비동기 조치 메소드를 보여줍니다.

[AsyncTimeout(2500)]
[HandleError(ExceptionType = typeof(TaskCanceledException), View = "TimedOut")]
public async Task Index(string city, CancellationToken cancellationToken) {
    var newsService = new NewsService();
    var sportsService = new SportsService();

    return View("Common", new PortalViewModel {
      NewsHeadlines = await newsService.GetHeadlinesAsync(cancellationToken),
      SportsScores = await sportsService.GetScoresAsync(cancellationToken)
    });
}

도움이 되었기를 바랍니다. 감사


를 통해 이동하시기 바랍니다 모든 MVC 4의 새로운 기능에 대한 URL


MVC 3

  1. NuGet을 통해 확장 가능한 통합 스캐 폴딩 시스템
  2. HTML 5 지원 프로젝트 템플릿
  3. 새로운 Razor View Engine을 포함한 표현 적 뷰
  4. 종속성 주입 및 전역 작업 필터가있는 강력한 후크
  5. Rich JavaScript support with unobtrusive JavaScript, jQuery Validation, and JSON binding

MVC 4

  1. ASP.NET Web API
  2. Refreshed and modernized default project templates
  3. New mobile project template
  4. Many new features to support mobile apps
  5. Enhanced support for asynchronous methods

Ref : http://dotnet-developers-cafe.blogspot.in/2013/09/difference-between-aspnet-mvc-3-and-mvc.html


Please check the below links to find out the differences.

http://forums.asp.net/t/1753017.aspx

http://www.askamoeba.com/Answer/130/Whats-new-in-MVC4-MVC3-Vs-MVC4

http://forums.asp.net/t/1918539.aspx?Main+difference+between+regular+webapplication+mvc3+and+mvc4+


One of the important feature introduced in MVC 4.0 was of Asynchronous controllers which enables to write the asynchronous action methods. Asynchronous controller allows an operation to get performed without making the working thread idle.

When an asynchronous action is invoked, the following steps occur:

The Web server gets a thread from the thread pool (the worker thread) and schedules it to handle an incoming request. This worker thread initiates an asynchronous operation. The worker thread is returned to the thread pool to service another Web request. When the asynchronous operation is complete, it notifies ASP.NET. The Web server gets a worker thread from the thread pool (which might be a different thread from the thread that started the asynchronous operation) to process the remainder of the request, including rendering the response.

Converting Synchronous Action Methods to Asynchronous Action Methods

Following is the example of synchronous action method and the its asynchronous equivalent version.

Synchronous Controller:

 public class TestController : Controller
 {
   public ActionResult Index()
    {
     return View(); 
    }
 }

Asynchronous variant of above operation:

public class TestController : AsyncController
{
   public void IndexAsync()
   {
    return View();
   }

  public ActionResult IndexCompleted()
  {
   return View();
  }
}

Steps:

  • Synchronous Controllers are the classes derived from the Controller class to implement an AsyncController instead of deriving the controller from Controller, derive it from AsyncController class. Controllers that derive from AsyncController enable ASP.NET to process asynchronous requests, and they can still service synchronous action methods.

  • Corresponding to the synchronous action method in Synchronous controller you need to create two methods for the action in asynchronous controller.First method that initiates the asynchronous process must have a name that consists of the action and the suffix "Async". The other method that is invoked when the asynchronous process finishes (the callback method) must have a name that consists of the action and the suffix "Completed".

    In the above sample example, the Index action has been turned into two methods in asynchronous controller: IndexAsync and IndexCompleted.

    The IndexAsync method returns void while the IndexCompleted method returns an ActionResult instance. Although the action consists of two methods, it is accessed using the same URL as for a synchronous action method (for example, Controller/Index).

Note the following about asynchronous action methods:

If the action name is Sample, the framework will look for SampleAsync and SampleCompleted methods.

View pages should be named Sample.aspx rather than SampleAsync.aspx or SampleCompleted.aspx. (The action name is Sample, not SampleAsync)

A controller cannot contain an asynchronous method named SampleAsync and a synchronous method named Sample. If it does, an AmbiguousMatchException exception is thrown because the SampleAsync action method and the Sample action method have the same request signature.

For more details click here : http://www.counsellingbyabhi.com/2014/05/asynchronous-controllers-in-aspnet-mvc.html

참고URL : https://stackoverflow.com/questions/12535327/difference-between-asp-net-mvc-3-and-4

반응형