简体   繁体   中英

ASP.NET Core IIS deployment errors

I have made an ASP.NET Core which is fully developed and ready for deployment on IIS. It will run on a local LAN network, but after publishing it is giving me a lot of errors (I am already trying for 4 full days to publish it on the local LAN network tho.)

the command I use for test running the .dll file is:

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

The first error I get after test running the .dll file is:

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

Which says that it can't read the connectionString although its set in Appsettings.json.

The second error I get is:

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

Which says that it cant run the Configure method inside of Startup.cs?

Don't know what to do know....

The full error log from CMD: https://pastebin.com/tsH5UQT5

Below my web.config, startup.cs and publish profile:

<?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
            //});
        }

The publish profile:

发布个人资料

The .NET Core server runtime packes are all installed correctly by the way.

Thanks in advance for anyone who could help me.

There is a guid on Hosting ASP.NET Core on Windows with IIS , have you Installed the asp .net core hosting bundle ?

May be a case of just running through this guide

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM