【问题标题】:ASP.NET Core IIS deployment errorsASP.NET Core IIS 部署错误
【发布时间】:2019-10-09 22:29:21
【问题描述】:

我已经制作了一个 ASP.NET Core,它已经完全开发并准备好在 IIS 上部署。它将在本地 LAN 网络上运行,但发布后它给了我很多错误(我已经尝试了整整 4 天在本地 LAN 网络上发布它。)

我用来测试运行.dll文件的命令是:

"C:\Program Files\dotnet\dotnet.exe" "C:\Users\HP\Desktop\bespaarttoppers\bespaartoppers.dll"

我在测试运行 .dll 文件后遇到的第一个错误是:

Application startup exception: System.AggregateException: One or more errors occurred. (Value cannot be null.
Parameter name: connectionString) ---> System.ArgumentNullException: Value cannot be null.

虽然它在 Appsettings.json 中设置,但它无法读取 connectionString。

我得到的第二个错误是:

Web.config

at applicationname.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider) in C:\Users\HP\source\repos\bespaartoppers-V2\bespaartoppers\Startup.cs:line 147

哪个说它不能在 Startup.cs 中运行 Configure 方法?

不知道怎么办才知道....

来自 CMD 的完整错误日志:https://pastebin.com/tsH5UQT5

在我的 web.config、startup.cs 和发布配置文件下方:

<?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=".\bespaartoppers.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
    </system.webServer>
  </location>
</configuration>
    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.AddSingleton<IConfiguration>(Configuration);

            // Add localization
            services.AddLocalization(options => options.ResourcesPath = "Resources");

            services.Configure<RequestLocalizationOptions>(options =>
            {
                var supportedCultures = new[]
                {
                new CultureInfo("nl-NL"),
                };

                options.DefaultRequestCulture = new RequestCulture(culture: "nl-NL", uiCulture: "nl-NL");
                options.SupportedCultures = supportedCultures;
                options.SupportedUICultures = supportedCultures;
            });

            CultureInfo.CurrentCulture = new CultureInfo("nl-NL");

            services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => false;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(
            Configuration.GetConnectionString("defaultconnection")));

            //services.AddDbContext<ApplicationDbContext>(options =>
            //options.UseSqlServer(
            //Configuration.GetConnectionString("")));

            //Originele Identity user manier
            //services.AddDefaultIdentity<IdentityUser>()
            //    .AddEntityFrameworkStores<ApplicationDbContext>();

            //Vernieuwde Identityuser manier i.v.m. Role based Authorization
            services.AddIdentity<IdentityUser, IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();

            //Login redirect juiste manier
            //services.ConfigureApplicationCookie(options => options.LoginPath = "~/Areas/Identity/Pages/Account/login");
            //services.ConfigureApplicationCookie(options => options.LogoutPath = "~/Areas/Identity/Pages/Account/logout");
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
                .AddRazorPagesOptions(options =>
                {
                    options.AllowAreas = true;
                    options.Conventions.AuthorizeAreaFolder("Identity", "/Account/Manage");
                    options.Conventions.AuthorizeAreaPage("Identity", "/Account/Logout");
                });

            services.ConfigureApplicationCookie(options =>
            {
                options.LoginPath = $"/Identity/Account/Login";
                options.LogoutPath = $"/Identity/Account/Logout";
                options.AccessDeniedPath = $"/Identity/Account/AccessDenied";
            });

            services.Configure<IISOptions>(options =>
            {
                options.AutomaticAuthentication = false;
            });
        }


        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider)
        {


            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

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

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

            app.UseAuthentication();

            CreateRoles(serviceProvider).Wait();

            //CultureInfo[] supportedCultures = new[] { new CultureInfo("nl") };
            //app.UseRequestLocalization(new RequestLocalizationOptions()
            //{
            //    DefaultRequestCulture = new RequestCulture(new CultureInfo("nl")),
            //    SupportedCultures = supportedCultures,
            //    SupportedUICultures = supportedCultures
            //});
        }

发布配置文件:

顺便说一下,.NET Core 服务器运行时包都安装正确了。

提前感谢任何可以帮助我的人。

【问题讨论】:

  • 请发布 Startup.cs:line 147
  • 看起来你的堆栈跟踪是关于“实体框架”设置的,它没有连接字符串。从startup.cs看不到服务配置,无法定位问题。
  • 用整个 startup.cs @mexanich 更新了帖子
  • 看起来您传递给 EF 的 DbContext 的连接字符串为空。
  • 不是,已经尝试硬编码值中的连接字符串。在本地它运行良好,但每当我部署时,它就会中断。你有什么建议来解决它? @桑德

标签: c# asp.net iis deployment


【解决方案1】:

Hosting ASP.NET Core on Windows with IIS 上有一个向导,你有Installed the asp .net core hosting bundle 吗?

可能只是通过本指南运行

希望对你有帮助

【讨论】:

  • 按照指南进行操作,是的,我已经安装了最新版本的托管包。
猜你喜欢
  • 2020-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-25
  • 2017-02-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多