Saltar al contenido principal

 none
Cómo migrar de ASP.NET MVC to ASP.NET Core ? RRS feed

  • Pregunta

  • fuente: https://hackernoon.com/how-to-migrate-project-from-aspnet-mvc-to-aspnet-core-qt1ks31zn
    POR QUÉ MIGRAR?

    ASP.NET Core is already a fairly well-known and developed framework with
    several major updates making it quite stable, technologically advanced
    and resistant to XSRF/CSRF attacks.

    Además, es Cross-platform. Podemos tener web application ejecutándose en Windows y Unix.
    Modular architecture - ASP.NET Core soporta NuGet packages.

    Rendimiento: ASP.NET Core handles 2.300% more requests per second than ASP.NET 4.6, and 800% more requests per second than node.js.

    https://www.techempower.com/benchmarks/#section=test&runid=8ca46892-e46c-4088-9443-05722ad6f7fb&hw=ph&test=plaintext

    https://github.com/aspnet/benchmarks




    *PREGUNTA 1* Igual de rendimiento ASP.NET Core en Windows que en Unix? Igual de rendimiento ASP.NET Core en Windows con IIS ?

    Step 1. Preparing a toolkit
    upgrade Visual Studio 2017 to version 15.3 or later and install the latest version of .NET Core SDK.

    https://docs.microsoft.com/en-us/dotnet/standard/analyzers/portability-analyzer

    Step 2. NuGet package compatibility analysis to support .Net standard

    NO todos los paquetes Nuget son compatibles con NET Core. Puede ser un gran problema.

    https://github.com/NuGetPackageExplorer/NuGetPackageExplorer

    Step 3. The new format of csproj file in .NET Core 

    A new approach for adding references to third-party packages was introduced in .NET Core.

    project.json vs csproj

    https://docs.microsoft.com/en-us/dotnet/core/tools/project-json-to-csproj

    https://docs.microsoft.com/en-us/dotnet/core/tools/csproj



    Step 4. Namespace update
    Delete all uses of System.Web and replace them with Microsoft.AspNetCore.

    NADA de System.Web (OJO...)


    Step 5. Configure the Startup.cs file instead of using global.asax

    Global.asax YA NO SE UTILIZA ??

    `The app entry point is Startup, and there is no dependency on the Global.asax file.`
    `Startup registers the middlewares in the app.`
    `Startup must include the Configure method. The required middleware should be added to the pipeline in Configure.`

    Issues to solve in Startup.cs:

        Configuring middleware for MVC and WebAPI requests

        Configuring for:

       
    Exception handling. You will inevitably face various collisions during
    porting, thus be ready and set up exception handling in the development
    environment. With UseDeveloperExceptionPage, we add middleware to catch
    exceptions.
        MVC routing. Registration of new routes has also been
    changed. IRouteBuilder is now used instead of RouteCollection, as a new
    way to register restrictions  (IActionConstraint)
        MVC/WebAPI filters. The filters should be updated in accordance with the new implementation of ASP.NET Core.
        MVC/WebAPI Formatters
        Binding models

        Areas. To include Area in an ASP.NET Core app, add a regular route to the Startup.cs file. For example, this way it will look for configuring Admin/ area

        Validation
    IFormCollection should not be passed to the controllers since in this case, asp.net
    server validation is disabled - MVC is suppressing further validation
    if the IFormCollection is found to be not null. To solve the problem,
    this property might be added to the model, this will prevent us from
    passing directly to the controller method.



    Step 6. Migrate HTTP handlers and HttpModules to Middleware

    https://msdn.microsoft.com/library/ms227673.aspx


    Step 7. Using built-in DI

    To inject dependencies, we used IoC (Inversion of Control) containers. In ASP.NET
    Core, such a container is represented by the IServiceProvider
    interface. Services are installed in the app in the
    Startup.ConfigureServices() method.
    Any registered service can be configured with three scopes:

        transient
        scoped
        singleton

    Step 8. Using WebAPI project compatibility shells (Shim)

    To simplify migration of an existing Web API, we advise using the NuGet package  Microsoft.AspNetCore.Mvc.WebApiCompatShim.


    Step 9. Porting Application Configuration

    Now we use a new approach based on the key-value pairs set by configuration providers. This is the recommended method in ASP.NET Core, and we use the appsettings.json file

    https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/index?tabs=basicconfiguration&view=aspnetcore-2.2

    You can also use the NuGet package

    System.Configuration.ConfigurationManager

    if for some reason you want to continue using *.config. In this case, the app cannot run on Unix platforms, but on IIS only.

    YA NO HAY web.config, sino appsettings.json



    *PREGUNTA 2* Se puede utilizar web.config (system.webserver, etc) con ASP.NET Core pero SOLAMENTE EN IIS Windows?



    Step 10. Porting static content to wwwrootTo
    serve static content, specify to web host the content root of the
    current directory. The default is wwwroot. You can configure your folder
    for storing static files by setting up middleware.


    Step 11. Porting EntityFramework to EF CoreEF Core vs Dapper ? Dapper in NET Core ?



    Step 12. Removing all HttpContext references and replacing obsolete classes and changing the namespace

    TODAS LAS CLASES de System.Web tienen sustituto en NET CORE ?



    Step 14. JS/CSS update

    Step 15. Porting views
    *Algún comentario sobre migración real-world de MVC a net Core?*


    jueves, 17 de octubre de 2019 21:10

Todas las respuestas

  • hola

    es una pregunta o un tutorial lo que publicas ?

    >>TODAS LAS CLASES de System.Web tienen sustituto en NET CORE ?

    creo que eso deberas evaluarlo, la funcionalidad principal seguro este soportada, pero seguro mucho habra cambiado y debas adaptarlo

    >>*Algún comentario sobre migración real-world de MVC a net Core?*

    particularmente no tengo y hay que evaluar porque quieres migrar, sino vas a usar ningun ventaja multiplataforma o quizas con container quizas ni necesites realizar ninguna migracion

    quizas lo que convenga es ir analizando funcionalidad y convertir completo, depende de que quieras convertir o usar como mejora, un ejemplo en asp.net core se usan los tag helpers, pero en versiones anteriores estos no existian, si quieres usarlos vas a tener que convertir el html de la view razor por completo

    saludos



    Leandro Tuttini

    Blog
    MVP Profile
    Buenos Aires
    Argentina

    viernes, 18 de octubre de 2019 0:12
  • Esto es muy goloso:

    Rendimiento: ASP.NET Core handles 2.300% more requests per second than ASP.NET 4.6, and 800% more requests per second than node.js.
    viernes, 18 de octubre de 2019 17:57