Asp.net core ASP.NET核心应用未在IIS上运行-错误执行请求时发生未处理的异常

Asp.net core ASP.NET核心应用未在IIS上运行-错误执行请求时发生未处理的异常,asp.net-core,error-handling,startup,Asp.net Core,Error Handling,Startup,我有一个ASP.NET核心项目和同一解决方案中的其他项目,该应用程序在开发过程中运行良好(“localhost:8000”),但当我在Windows 10上将其发布到IIS(“localhost”)时,只要尝试输入url,页面就为空 我打开事件查看器并给出“已成功启动”: 我打开了logs文件夹,看到一个错误: 2020-10-25 15:01:17.4578用户网络程序调试初始化主 2020-10-25 15:01:17.8481 Microsoft.Hosting.Lifetime INF

我有一个ASP.NET核心项目和同一解决方案中的其他项目,该应用程序在开发过程中运行良好(“localhost:8000”),但当我在Windows 10上将其发布到IIS(“localhost”)时,只要尝试输入url,页面就为空

我打开事件查看器并给出“已成功启动”:

我打开了logs文件夹,看到一个错误:

2020-10-25 15:01:17.4578用户网络程序调试初始化主 2020-10-25 15:01:17.8481 Microsoft.Hosting.Lifetime INFO应用程序已启动。按Ctrl+C组合键关闭。 2020-10-25 15:01:17.8490 Microsoft.Hosting.Lifetime INFO托管环境:生产 2020-10-25 15:01:17.8490 Microsoft.Hosting.Lifetime信息内容根路径:D:\web 2020-10-25 15:01:17.9013 Microsoft.AspNetCore.Diagnostics.ExceptionHandler中间件错误执行请求时发生未经处理的异常。 2020-10-25 15:01:17.9013 Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware错误试图执行错误处理程序时引发异常。 2020-10-25 15:01:17.9013 Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer错误连接ID“18230571301796315146”,请求ID“8000000b-0002-fd00-b63f-84710c7967bb”:应用程序引发了未经处理的异常

有时我会在日志中看到此错误:

2020-10-25 16:11:05.3851用户网络程序调试初始化主 2020-10-25 16:11:05.7869 Microsoft.Hosting.Lifetime INFO应用程序已启动。按Ctrl+C组合键关闭。 2020-10-25 16:11:05.7869 Microsoft.Hosting.Lifetime信息托管环境:生产 2020-10-25 16:11:05.7869 Microsoft.Hosting.Lifetime信息内容根路径:D:\web 2020-10-25 16:11:05.8245 Microsoft.AspNetCore.Session.SessionMiddleware警告取消保护会话cookie时出错。 2020-10-25 16:11:05.8419 Microsoft.AspNetCore.Diagnostics.ExceptionHandler中间件错误执行请求时发生未经处理的异常。 2020-10-25 16:11:05.8419Microsoft.AspNetCore.Session.SessionMiddleware取消保护会话cookie时出现警告错误。 2020-10-25 16:11:05.8419 Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware错误试图执行错误处理程序时引发异常。 2020-10-25 16:11:05.8419 Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer错误连接ID“18230571301796315163”,请求ID“800001C-0002-fd00-b63f-84710c7967bb”:应用程序引发了未经处理的异常

因此,我认为其中有一些东西:

Microsoft.AspNetCore.Session.SessionMiddleware警告取消保护会话cookie时出错

这是我的Startup.cs:

using DataManager.Clients;
using DataManager.DataManagers;
using DataManager.Entities;
using DataManager.Interfaces;
using DataManager.Managers;
using DataManager.Managers.SwedishBankId;
using DataManager.SqlLiteDatabase;
using DataManager.SqlLiteDatabase.Interfaces;
using DataManager.SqlLiteDatabase.Schema;
using MaxMind.GeoIP2;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using MStart.Constants;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using UserWeb.Controllers;
using UserWeb.Services;
using WebDataManager;

namespace UserWeb
{
    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.AddControllersWithViews(options =>
            {
                options.Filters.Add(typeof(onLoadActionFilter));
            });

            services.AddHttpClient();

            services.AddDistributedMemoryCache();
            services.AddSession(options =>
            {
                options.IdleTimeout = TimeSpan.FromMinutes(31);
                options.Cookie.IsEssential = true;
            });

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(config =>
            {
                config.Cookie.Name = "M_User";
                config.LoginPath = "/Home/Login";
                //config.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
                config.ExpireTimeSpan = new TimeSpan(0, 30, 0);
            });

            services.AddLocalization();

            services.Configure<RequestLocalizationOptions>(
                options =>
                {
                    var supportedCultures = new List<CultureInfo>
                    {
                        new CultureInfo("en"),
                        new CultureInfo("ar"),
                        new CultureInfo("ru"),
                        new CultureInfo("fr"),
                        new CultureInfo("es"),
                    };

                    options.DefaultRequestCulture = new RequestCulture(culture: "en", uiCulture: "en");
                    options.SupportedCultures = supportedCultures;
                    options.SupportedUICultures = supportedCultures;
                    options.RequestCultureProviders = new[] { new RouteDataRequestCultureProvider { IndexOfCulture = 1, IndexofUICulture = 1 } };
                });

            // Configure to read configuration options from MaxMind section
            services.Configure<WebServiceClientOptions>(Configuration.GetSection("MaxMind"));

            // Configure dependency injection for WebServiceClient
            services.AddHttpClient<WebServiceClient>();

            services.AddMvc().AddViewLocalization();

            services.Configure<RouteOptions>(options =>
            {
                options.ConstraintMap.Add("culture", typeof(LanguageRouteConstraint));
            });

            services.AddHttpContextAccessor();

            ////////////////////////////////////

            MStartConstants.IsWebPlatform = true;
            //ResultManager.Current.LoadWebResources();
            services.AddControllersWithViews().AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);
            services.AddScoped<IWebUserPreferences, WebUserPreferences>();
            services.AddScoped<ICacheContext, CacheContext>();
            services.AddScoped<IEventDispatcher, EventDispatcher>();
            services.AddScoped<IMemoryStorage<CommonTable>, MemoryStorage>();
            services.AddScoped<IDataManager, UserDataManager>();
            services.AddScoped<IContext<UserContext>, UserContext>();
            services.AddScoped<INetworkService, NetworkService>();
            services.AddScoped<IProgramClient, ProgramClient>();
            services.AddScoped<IUserClient, UserClient>();
            services.AddScoped<IAccountClient, AccountClient>();
            services.AddScoped<IBINClient, BINClient>();
            services.AddScoped<ITransactionClient, TransactionClient>();
            services.AddScoped<ISQLite, SQLiteService>();
            services.AddScoped<ISqliteStorage, SqliteStorage>();
            services.AddScoped<IUserManager, UserManager>();
            services.AddScoped<ILocalStorage<CommonTable>, WebDataManager.LocalStorage>();
            services.AddScoped<IGroupClient, GroupClient>();
            services.AddScoped<ICatalogClient, CatalogClient>();
            services.AddScoped<IOrderClient, OrderClient>();
            services.AddScoped<IMessageClient, MessageClient>();
            services.AddScoped<ISwedishBankIdManager, SwedishBankIdManager>();
            services.AddScoped<ISettings, WebSettings>();
            services.AddScoped<IWebDomainService, WebDomainService>();
        }

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

            app.UseRouting();


            var localizationOptions = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>().Value;
            app.UseRequestLocalization(localizationOptions);


            app.UseAuthentication();
            app.UseAuthorization();

            app.UseSession();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "Culture",
                    pattern: "{culture}/{controller=Home}/{action=Login}/{id?}");

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Login}/{id?}");
            });

            var files = Directory.GetFiles("..\\DataManager\\ProgramConfig", "*", SearchOption.AllDirectories);
            SiteConfiguration siteConfiguration = new SiteConfiguration();
            List<WebConfiguration> webConfigurationsList = new List<WebConfiguration>();
            WebConfiguration webConfiguration = null;
            foreach (var item in files)
            {
                if (item.ToLower().Contains("programconfig.json"))
                    webConfiguration = new WebConfiguration();

                var jsonString = System.IO.File.ReadAllText(item);
                if (item.ToLower().Contains("programconfig.json"))
                {
                    ProgramConfiguration programConfig = JsonConvert.DeserializeObject<ProgramConfiguration>(jsonString);
                    webConfiguration.programConfigurations = programConfig;
                }
                else
                {
                    Theme theme = JsonConvert.DeserializeObject<Theme>(jsonString);
                    webConfiguration.programThemes = theme;
                }
                if (item.ToLower().Contains("theme.json"))
                    webConfigurationsList.Add(webConfiguration);
            }
            siteConfiguration.webConfigurations = webConfigurationsList;
            CacheSettings.ProgramConfigurationTTL = Convert.ToInt32(Configuration.GetSection("SystemCacheTTL").GetSection("ProgramConfigurationTTL").Value);
            var _cacheContext = serviceProvider.GetService<ICacheContext>();
            _cacheContext.Insert("SiteConfiguration", siteConfiguration, CacheSettings.ProgramConfigurationTTL);
        }
    }
}
使用DataManager.Clients;
使用DataManager.DataManagers;
使用DataManager.Entities;
使用DataManager.Interfaces;
使用DataManager.Managers;
使用DataManager.Managers.SwedishBankId;
使用DataManager.SqlLiteDatabase;
使用DataManager.SqlLiteDatabase.Interfaces;
使用DataManager.SqlLiteDatabase.Schema;
使用MaxMind.GeoIP2;
使用Microsoft.AspNetCore.Authentication.Cookies;
使用Microsoft.AspNetCore.Builder;
使用Microsoft.AspNetCore.Hosting;
使用Microsoft.AspNetCore.Http;
使用Microsoft.AspNetCore.Localization;
使用Microsoft.AspNetCore.Routing;
使用Microsoft.Extensions.Configuration;
使用Microsoft.Extensions.DependencyInjection;
使用Microsoft.Extensions.Hosting;
使用Microsoft.Extensions.Options;
使用MStart.Constants;
使用Newtonsoft.Json;
使用制度;
使用System.Collections.Generic;
利用制度全球化;
使用System.IO;
使用UserWeb.Controllers;
使用UserWeb.Services;
使用WebDataManager;
命名空间用户网
{
公营创业
{
公共启动(IConfiguration配置)
{
配置=配置;
}
公共IConfiguration配置{get;}
//此方法由运行时调用。请使用此方法将服务添加到容器中。
public void配置服务(IServiceCollection服务)
{
services.addcontrollerswithview(选项=>
{
options.Filters.Add(typeof(onLoadActionFilter));
});
services.AddHttpClient();
AddDistributedMemoryCache();
services.AddSession(选项=>
{
options.IdleTimeout=TimeSpan.frommins(31);
options.Cookie.IsEssential=true;
});
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(config=>
{
config.Cookie.Name=“M_User”;
config.LoginPath=“/Home/Login”;
//config.ReturnUrlParameter=CookieAuthenticationDefaults.ReturnUrlParameter;
config.ExpireTimeSpan=新的时间跨度(0,30,0);
});
services.AddLocalization();
服务。配置(
选项=>
{
var supportedCultures=新列表
{
新文化信息(“en”),
新文化信息(“ar”),
新文化信息(“ru”),
新文化资讯(“fr”),
新文化信息(“es”),
};
options.DefaultRequestCulture=新的RequestCulture(区域性:“en”,uiCulture:“en”);
options.SupportedCultures=SupportedCultures;
options.supportedCultures=supportedCultures;
options.RequestCultureProviders=new[]{new RouteDataRequestCultureProvider{IndexOfCulture=1,IndexOfCulture=1}};
});
//配置以从MaxMind部分读取配置选项
services.Configure(Configuration.GetSection(“MaxMind”);
//为WebServiceClient配置依赖项注入
services.AddHttpClient();
services.AddMvc(