ASP.NET核心应用不运行在localhost

问题描述 投票:0回答:1

我试图运行与ASP.NET CoreAngular。虽然能够配置Angular项目,遗憾的是ASP.NET Core项目成功运行,但得到在浏览器中如下:

HTTP Error 502.5 - Process Failure

Common causes of this issue:
The application process failed to start
The application process started but then stopped
The application process started but failed to listen on the configured port

让我写,我与当前一个相同的配置成功运行该项目另一台PC。这两个具有相同的核心版本 - 2.2。我不知道为什么我收到上述但期望的一些想法,寻求解决办法。

Startup.cs:

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

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.Configure<CookiePolicyOptions>(options =>
        {
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });


        #region MyRegion
        var connection = Configuration.GetConnectionString("DatabaseConnection");
        services.AddDbContext<DatabaseContext>(options => options.UseSqlServer(connection, b => b.UseRowNumberForPaging()));

        var appSettingsSection = Configuration.GetSection("AppSettings");
        services.Configure<AppSettings>(appSettingsSection);

        // configure jwt authentication
        var appSettings = appSettingsSection.Get<AppSettings>();
        var key = Encoding.ASCII.GetBytes(appSettings.Secret);
        services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata = false;
                x.SaveToken = true;
                x.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey = new SymmetricSecurityKey(key),
                    ValidateIssuer = false,
                    ValidateAudience = false
                };
            });


        services.AddSingleton<IConfiguration>(Configuration);       
        services.AddTransient<ISchemeMaster, SchemeMasterConcrete>();
        services.AddTransient<IPlanMaster, PlanMasterConcrete>();
        services.AddTransient<IPeriodMaster, PeriodMasterConcrete>();
        services.AddTransient<IRole, RoleConcrete>();
        services.AddTransient<IMemberRegistration, MemberRegistrationConcrete>();
        services.AddTransient<IUsers, UsersConcrete>();
        services.AddTransient<IUsersInRoles, UsersInRolesConcrete>();
        services.AddTransient<IPaymentDetails, PaymentDetailsConcrete>();
        services.AddTransient<IRenewal, RenewalConcrete>();
        services.AddTransient<IReports, ReportsMaster>();
        services.AddTransient<IGenerateRecepit, GenerateRecepitConcrete>();
        services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
        services.AddScoped<IUrlHelper>(implementationFactory =>
        {
            var actionContext = implementationFactory.GetService<IActionContextAccessor>().ActionContext;
            return new UrlHelper(actionContext);
        });
        #endregion

        // Start Registering and Initializing AutoMapper

        Mapper.Initialize(cfg => cfg.AddProfile<MappingProfile>());
        services.AddAutoMapper();

        // End Registering and Initializing AutoMapper

        services.AddMvc(options => { options.Filters.Add(typeof(CustomExceptionFilterAttribute)); })            
        .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)      
        .AddJsonOptions(options =>
        {
            options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
        });
        services.AddCors(options =>
        {
            options.AddPolicy("CorsPolicy",
                builder => builder.AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials()
                    .WithExposedHeaders("X-Pagination"));
        });
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }

        app.UseStaticFiles();
        app.UseCookiePolicy();
        app.UseAuthentication();

        app.UseCors("CorsPolicy");
        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
}

Program.cs中:

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>();
}

appsettings.json:

{
  "AppSettings": {
    "Secret": "6XJCIEJO41PQZNWJC4RR"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "DatabaseConnection": "Data Source=.;Database=SampleDB;"
  }
}

更新:这是2.2版本。跳过了初始的那部分。

asp.net asp.net-core visual-studio-2017 asp.net-core-2.1
1个回答
0
投票

这是解决一个愚蠢的问题。虽然让若有人面临这个问题我写,只是检查错误日志或输出窗口中看到所需要的工具或.NET Core版本。就我而言,我忘了安装.NET Core 2.2,这里是下面的链接:

.NET Core 2.2 SDK

谢谢大家谁评论整理了这一点。

© www.soinside.com 2019 - 2024. All rights reserved.