Skip to content

Instantly share code, notes, and snippets.

@RickStrahl
Last active November 7, 2021 05:47
Show Gist options
  • Save RickStrahl/8ba3985bbd6010d9c238e71b73ea4e68 to your computer and use it in GitHub Desktop.
Save RickStrahl/8ba3985bbd6010d9c238e71b73ea4e68 to your computer and use it in GitHub Desktop.
ASP.NET Core Live Reload not working with this basic startup
using LicensingService.Configuration;
using Microsoft.AspNetCore.Authentication.Cookies;
using Newtonsoft.Json.Serialization;
using Westwind.AspNetCore.LiveReload;
using Westwind.Licensing;
using Westwind.Utilities.Data;
var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;
var configuration = builder.Configuration;
var host = builder.Host;
// Set up Configuration so we can use App.Configuration or inject ApplicationConfiguration
var config = new ApplicationConfiguration();
configuration.Bind("Application", configuration);
services.AddSingleton(configuration);
App.Configuration = config;
var licenseConfig = new LicenseConfiguration();
configuration.Bind("Licensing", licenseConfig);
if (string.IsNullOrEmpty(licenseConfig.ConnectionString))
licenseConfig.ConnectionString = config.LicenseServerConnectionString;
LicenseConfiguration.Current = licenseConfig;
services.AddSingleton(LicenseConfiguration.Current);
services.AddTransient<LicenseSqlDataManager>();
// services.AddLiveReload(); // Westwind.AspNetCore.LiveReload services
services.AddAuthentication(options =>
{
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
}).AddCookie(options => { options.LoginPath = "/admin/login"; });
// for ASP.NET Core 3.x and later, add Runtime Razor Compilation if using anything Razor
services.AddRazorPages(options =>
{
options.Conventions.AuthorizeFolder("/admin");
options.Conventions.AllowAnonymousToPage("/admin/login");
});
services.AddControllers()
// Use classic JSON
.AddNewtonsoftJson(opt =>
{
var resolver = opt.SerializerSettings.ContractResolver;
if (resolver != null)
{
var res = resolver as DefaultContractResolver;
res.NamingStrategy = new CamelCaseNamingStrategy();
}
opt.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
if ( builder.Environment.IsDevelopment())
opt.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
});
var app = builder.Build();
//app.UseLiveReload(); // Westwind.AspNetCore.LiveReload (not used)
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.MapRazorPages();
app.Run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment