Website Deployment via IIS : Can't access site

倖福魔咒の 提交于 2020-04-17 23:41:20

问题


I created a site using IIS, after installing .NET Hosting Bundle on server. However, I am not able to access the site with the browser via url. Google Chrome gave the error DNS_PROBE_FINISHED_NXDOMAIN.

So,I added a binding to localhost:443, and accessed the site from the server computer. However an error appeared in the browser: HTTP 502.5. It appears that the IIS reads the http requests, as may be seen in the log.

Here is my web.config file:

<?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-->

The Program.cs file is:

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");
                    });
                });
    }
}

Here I show the log of the IIS site:

#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

Next I show my 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();

        }
    }
}

Could you help me?


回答1:


@salli I accessed the site via https://localhost:443/ since I had added this binding. However, besides the error in the certificate (the certificate is issued to something like *.my.me), I have an error in the launching of the app. Here I show the log of the site:

#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

Next I show my 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();

        }
    }
}

Could you help me?

EDIT

I solved this problem enabling logging in my app web.config as following:

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

Then I was able to see the error in the log files in .\logs directory.



来源:https://stackoverflow.com/questions/59986062/website-deployment-via-iis-cant-access-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!