且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过 IIS 部署网站:无法访问站点

更新时间:2023-12-02 15:23:01

@salli 我通过 https://localhost 访问了该站点:443/ 因为我已经添加了这个绑定.但是,除了证书中的错误(证书颁发给 *.my.me 之类的东西)之外,我在启动应用程序时也有错误.这里我展示了网站的日志:

@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

接下来我展示我的 Startup.cs:

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();

        }
    }
}

你能帮我吗?

编辑

我解决了这个问题,允许登录我的应用程序 web.config 如下:

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

<aspNetCore processPath=".MVF2.exe" stdoutLogEnabled="true" stdoutLogFile=".logsstdout" />

然后我能够在 .logs 目录中的日志文件中看到错误.

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