首页 > 解决方案 > 尝试从 net core 2.2 迁移到 3.0

问题描述

早上好,我正在从 2.2 迁移到 3.0,然后使用 Visual Studio 2019 迁移到 Net Core 中的 3.1, 我的第一次尝试是最基本的:

微软的文档

虽然它是一个简化版本,但我将它添加到我的代码中,留下我仍然必须用于我的项目的包并且它不起作用......结果:404

第二次尝试:

err_connection_refused

更改 http 和 https 的 ip 项目,并将其与 .json 结果进行比较:404 ERR_CONNECTION_REFUSED

第三次尝试: 将 2.2 迁移到 3.0 stackoverlofw

尽可能减少它,但也没有成功

第四次尝试最“有希望

https://github.com/StackExchangeExamples/DotNetCoreTargetDotNetFramework/tree/master/BasicCoreWebsite

因为它展示了 3.0 版项目的外观“完整”示例

结果:显示“hello world”而不是 404 的页面不是成功但比 404 更好,不是吗?

这篇文章的想法不仅是为了解决我的情况,这样我就不会被踢出局(lol),而是为未来有同样问题的人创建尽可能多的完整功能示例。

非常感谢您,您需要的数据我会很高兴上传!

更新(我添加了startup.cs)

   using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption;
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using HistoriaClinica.IServicio;
using HistoriaClinica.IServicio.Servicio;
using System;
using System.IO.Compression;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Session;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace HistoriaClinica
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        /// <summary>
        ///  This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services"></param>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            //services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            services.AddHttpContextAccessor();
            services.AddDistributedMemoryCache();
            services.AddSession();

            services.Configure<ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
            });

            services.AddMemoryCache();

            services.AddSession(options => {
                options.IdleTimeout = TimeSpan.FromMinutes(30);
            });

            services.AddDataProtection().UseCryptographicAlgorithms(
                new AuthenticatedEncryptorConfiguration()
                {
                    EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
                    ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
                });

           // services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);


            services.AddResponseCompression(options =>
            {
                options.Providers.Add<GzipCompressionProvider>();
                options.EnableForHttps = true;
                options.MimeTypes = new[]
                {
                    // General
                    "text/plain",
                    // Static files
                    "text/css",
                    "application/javascript",
                    // MVC
                    "text/html",
                    "text/xml",
                    "application/json",
                    "text/json",
                    "image/png",
                    "image/jpeg",
                    "image/svg+xml",
                    "application/octet-stream",
                    "application/font-woff",
                    "application/pdf"
                };
            });

            services.Configure<GzipCompressionProviderOptions>(options =>
                options.Level = CompressionLevel.Optimal
                );

            services.AddMemoryCache();

            // Add application services.
            services.AddSingleton<ILoggerServicio, LoggerServicio>();
            services.AddScoped<IEncriptaServicio, EncriptaServicio>();
            services.AddSingleton<IHttpServicio, HttpServicio>();
            services.AddScoped<IPacienteServicio, PacienteServicio>();
            services.AddScoped<IProfesionalServicio, ProfesionalServicio>();
            services.AddScoped<IEspecialidadServicio, EspecialidadServicio>();
            services.AddScoped<ILaboratorioServicio, LaboratorioServicio>();
            services.AddScoped<IUsuarioServicio, UsuarioServicio>();
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton<ISessionServicio, SessionServicio>();
            services.AddScoped<IImagenServicio, ImagenServicio>();          
            services.AddScoped<INoticiaServicio, NoticiaServicio>();
            services.AddScoped<IResponseServicio, ResponseServicio>();
            services.AddScoped<IClienteServicio, ClienteServicio>();

           // services.AddMvc(options => options.EnableEndpointRouting = false);
            services.AddControllers(options => options.EnableEndpointRouting = false);
            services.AddControllersWithViews(options => options.EnableEndpointRouting = false);
            services.AddRazorPages().AddMvcOptions(options => options.EnableEndpointRouting = false);
            // Cron jobs
            //services.AddCronJob<RecordatorioTurno24>(c =>
            //{
            //    c.TimeZoneInfo = TimeZoneInfo.Local;
            //    c.CronExpression = @"*/1 * * * *";
            //});
            //services.AddCronJob<RecordatorioTurno48>(c =>
            //{
            //    c.TimeZoneInfo = TimeZoneInfo.Local;
            //    c.CronExpression = @"* * * * *";
            //});

            services.AddRazorPages();

        }

公共无效配置(IApplicationBuilder 应用程序,IWebHostEnvironment env){

        app.UseSession();

        app.UseSession();
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Cuenta/Error");
        }
        
        app.UseStaticFiles();

        app.UseRouting();

        app.UseCors();

        app.UseAuthentication();

        app.UseAuthorization();


        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "Default",
                template: "{controller=Cuenta}/{action=Login}/{id?}");

        });
     
        //app.UseEndpoints(endpoints =>
        //{
        //    endpoints.MapControllerRoute(
        //        name: "default",
        //        pattern: "{controller=Cuenta}/{action=Login}");
        //});

    }
}

}

标签: visual-studio.net-coremigration

解决方案


推荐阅读