Развертывание веб-сайта через IIS: невозможно получить доступ к сайту - PullRequest
0 голосов
/ 30 января 2020

Я создал сайт с помощью IIS, после установки. NET Hosting Bundle на сервере. Однако я не могу получить доступ к сайту через браузер через URL. Google Chrome дал ошибку DNS_PROBE_FINISHED_NXDOMAIN.

Итак, я добавил привязку к localhost:443 и получил доступ к сайту с сервера. Однако в браузере появилась ошибка: HTTP 502.5. Похоже, что IIS читает запросы http, как это можно увидеть в журнале.

Вот мой файл web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath=".\MVF2.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
    </system.webServer>
  </location>
</configuration>
<!--ProjectGuid: 99f7528d-8954-427a-86a5-7124668717df-->

Файл Program.cs:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

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

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .UseKestrel(options =>
                {
                    options.Listen(IPAddress.Loopback, 443, listenOptions =>
                    {
                        listenOptions.UseHttps("mycertificate.crt");
                    });
                });
    }
}

Здесь я показываю журнал сайта IIS:

#Software: Microsoft Internet Information Services 8.5
#Version: 1.0
#Date: 2020-01-30 14:35:38
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2020-01-30 14:35:38 ::1 GET / - 443 - ::1 Mozilla/5.0+(Windows+NT+6.3;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko - 502 5 2147500037 859
2020-01-30 14:44:14 ::1 GET / - 443 - ::1 Mozilla/5.0+(Windows+NT+6.3;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko - 502 5 2147500037 1078

Далее я показываю мой файл Startup.cs:

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

        public IConfiguration Configuration { get; }

        public AppFeatures features { get; set; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext<idDbContext>(options =>
            {
                var connectionString = Configuration.GetConnectionString("idDataContext");
                options.UseSqlServer(connectionString);
            });

            services.AddIdentity<AppUser, IdentityRole>(opts =>
            {
                opts.Password.RequiredLength = 6;
                opts.Password.RequireNonAlphanumeric = false;
                opts.Password.RequireLowercase = false;
                opts.Password.RequireUppercase = false;
                opts.Password.RequireDigit = false;
            }).AddEntityFrameworkStores<idDbContext>()
                .AddDefaultTokenProviders();

            services.ConfigureApplicationCookie(opts =>
            {
                opts.LoginPath = "/Login/Login";
                opts.AccessDeniedPath = "/Login/AccessDenied";
            });

            services.AddDbContext<fmDataContext>(options =>
            {
                var connectionString = Configuration.GetConnectionString("fmDataContext");
                options.UseSqlServer(connectionString);
            });

            services.AddTransient<AppFeatures>(x => (features = new AppFeatures
            {
                DevelopmentEnvironment = Configuration.GetValue<bool>("AppFeatures:DevelopmentEnvironment"),
                SqlServerCredentials = Configuration.GetConnectionString("fmDataContext")
            }));

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddMemoryCache();

            services.AddSession();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, 
                              IHostingEnvironment env, 
                              AppFeatures features)
        {
            app.UseExceptionHandler("/Error.html");

            if (features.DevelopmentEnvironment)
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseAuthentication();

            app.Use(async (context, next) =>
            {
                if (context.Request.Path.Value.Contains("error"))
                    throw new Exception("ERRO!");

                await next();
            });

            app.UseSession();

            app.UseMvc(routes =>
            {
                routes.MapRoute("Default",
                    "{controller=Home}/{action=Index}/{id?}");
            });

            app.UseFileServer();

            idDbContext.CreateAdminAccount(app.ApplicationServices, Configuration).Wait();

        }
    }
}

Не могли бы вы мне помочь?

1 Ответ

0 голосов
/ 30 января 2020

@ salli Я получил доступ к сайту через https://localhost: 443 / , так как я добавил эту привязку. Однако, помимо ошибки в сертификате (сертификат выдан для чего-то вроде * .my.me), у меня есть ошибка при запуске приложения. Здесь я показываю журнал сайта:

#Software: Microsoft Internet Information Services 8.5
#Version: 1.0
#Date: 2020-01-30 14:35:38
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2020-01-30 14:35:38 ::1 GET / - 443 - ::1 Mozilla/5.0+(Windows+NT+6.3;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko - 502 5 2147500037 859
2020-01-30 14:44:14 ::1 GET / - 443 - ::1 Mozilla/5.0+(Windows+NT+6.3;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko - 502 5 2147500037 1078

Далее я показываю мои Startup.cs:

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

        public IConfiguration Configuration { get; }

        public AppFeatures features { get; set; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext<idDbContext>(options =>
            {
                var connectionString = Configuration.GetConnectionString("idDataContext");
                options.UseSqlServer(connectionString);
            });

            services.AddIdentity<AppUser, IdentityRole>(opts =>
            {
                opts.Password.RequiredLength = 6;
                opts.Password.RequireNonAlphanumeric = false;
                opts.Password.RequireLowercase = false;
                opts.Password.RequireUppercase = false;
                opts.Password.RequireDigit = false;
            }).AddEntityFrameworkStores<idDbContext>()
                .AddDefaultTokenProviders();

            services.ConfigureApplicationCookie(opts =>
            {
                opts.LoginPath = "/Login/Login";
                opts.AccessDeniedPath = "/Login/AccessDenied";
            });

            services.AddDbContext<fmDataContext>(options =>
            {
                var connectionString = Configuration.GetConnectionString("fmDataContext");
                options.UseSqlServer(connectionString);
            });

            services.AddTransient<AppFeatures>(x => (features = new AppFeatures
            {
                DevelopmentEnvironment = Configuration.GetValue<bool>("AppFeatures:DevelopmentEnvironment"),
                SqlServerCredentials = Configuration.GetConnectionString("fmDataContext")
            }));

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddMemoryCache();

            services.AddSession();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, 
                              IHostingEnvironment env, 
                              AppFeatures features)
        {
            app.UseExceptionHandler("/Error.html");

            if (features.DevelopmentEnvironment)
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseAuthentication();

            app.Use(async (context, next) =>
            {
                if (context.Request.Path.Value.Contains("error"))
                    throw new Exception("ERRO!");

                await next();
            });

            app.UseSession();

            app.UseMvc(routes =>
            {
                routes.MapRoute("Default",
                    "{controller=Home}/{action=Index}/{id?}");
            });

            app.UseFileServer();

            idDbContext.CreateAdminAccount(app.ApplicationServices, Configuration).Wait();

        }
    }
}

Не могли бы вы мне помочь?

РЕДАКТИРОВАТЬ

Я решил эту проблему, включив вход в свое приложение web.config следующим образом:

<aspNetCore processPath=".\MVF2.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />

Затем я смог увидеть ошибку в файлах журналов в каталоге .\logs .

...