Last week I had the task of upgrading a project written in .NET Core 2.1 to .NET Core 3.1. I'll be posting solutions to the errors I came across. But first, I'll show important sections of my Startup.cs and Program.cs:
I'll start with Program.cs:
public static void Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
host.Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseLamar()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
}).ConfigureLogging(builder =>
{
...
builder.AddApplicationInsights();
});
On to the file Startup.cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureContainer(ServiceRegistry services)
{
services.Configure<CookiePolicyOptions>(options =>
{
...
});
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Con
services.AddMediatR();
services.AddAutoMapper();
services.AddSession();
...
services.AddControllersWithViews(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(typeof(AzureAuthorizationFilter));
...
options.UseModelBinding();
});
services.AddRazorPages().SetCompatibilityVersion(CompatibilityVersion.Latest).AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver())
.AddTypedRouting()
.AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);
services.AddAuthorization();
services.Configure<RazorViewEngineOptions>(options => {
...
});
services.AddSignalR();
services.Scan(scan =>
{
scan.TheCallingAssembly();
...
scan.WithDefaultConventions();
});
services.For<IPrincipal>().Use(x => Thread.CurrentPrincipal);
...
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseAuthentication();
app.UseSession();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
"default",
"{controller=Home}/{action=Index}/{id?}");
endpoints.MapHub<NotificationHub>("/pushHub");
});
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment