I am new to .net core development and I am trying to deploy the web app .net core 2.1 to IIS in windows 10. I have followed all the steps including creating applicationpool 'No Managed Code' and everything worked fine. Later after 2 days it stopped working then I redoployed my project using the release type to Debug and here I am getting this exception displayed in the brower which is the same in the log file.
However, the same app works fine in visual studio. My machine has the following .net packages installed. .Net Core Runtme 2.1.7(x64) .Net Core 2.1.7 - Windows Server Hosting .net Core Runtime 2.1.7(x86) .Net Core SDK 2.1.503 (x86) .Net Core SDK 2.1.503(x64) Microsoft Web Deploy 4.0
After going through all the articles available and tweaking and changing the app was finally worked but later it stopped working and giving the above error. My Startup.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; set; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
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.Configure<DataProtectionTokenProviderOptions>(o =>
{
o.Name = "Default";
o.TokenLifespan = TimeSpan.FromHours(1);
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseMySql(Configuration.GetConnectionString("DefaultConnection"),
mysqloptions => {
mysqloptions.ServerVersion(new Version(8, 0, 13), ServerType.MySql);
}));
services.AddTransient<IProductRepository, EFProductRepository>();
services.AddScoped<Cart>(sp => SessionCart.GetCart(sp));
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddIdentity<ApplicationUser, IdentityRole>(
options =>
{
options.Stores.MaxLengthForKeys = 128;
options.Tokens.PasswordResetTokenProvider = TokenOptions.DefaultAuthenticatorProvider;
options.SignIn.RequireConfirmedEmail = false;
options.Password.RequireDigit = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
}
)
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddRoleManager<RoleManager<IdentityRole>>()
.AddRoles<IdentityRole>()
//.AddDefaultUI();
.AddDefaultTokenProviders();
//Authentication
services.AddDbContext<MainContext>(options =>
options.UseMySql(Configuration.GetConnectionString("ModelConnectionString"),
mysqloptions => {
mysqloptions.ServerVersion(new Version(8, 0, 13), ServerType.MySql);
mysqloptions.MigrationsAssembly("GasStationApp");
}));
services.AddScoped<IUserClaimsPrincipalFactory<ApplicationUser>, MyUserClaimsPrincipalFactory>();
services.AddMvc().AddNToastNotifyToastr(new ToastrOptions()
{
ProgressBar = false,
PositionClass = ToastPositions.TopFullWidth
}
);
services.Configure<IISOptions>(options => {
options.AutomaticAuthentication = false;
options.ForwardClientCertificate = false;
});
My Program.cs
public class Program
{
public static int Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.RollingFile("logs/log-{Date}.txt")
.CreateLogger();
try
{
Log.Information("Starting web host");
BuildWebHost(args).Run();
return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
return 1;
}
finally
{
Log.CloseAndFlush();
}
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseKestrel()
.ConfigureAppConfiguration((builderContext, config) =>
{
config.AddJsonFile("appsettings.json", optional: false);
})
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseSerilog() // <-- Add this line
.Build();
}
The app works fine in VS2017 but does not work when deployed to IIS in Windows 10 Please help me resolve this issue. Any advice would be helpful. Thanks in advance.