Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created October 13, 2023 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/5258c79c5ec04f17803eb546bad5dc36 to your computer and use it in GitHub Desktop.
Save bjoerntx/5258c79c5ec04f17803eb546bad5dc36 to your computer and use it in GitHub Desktop.
private static void StartWebServer()
{
var assembly = Assembly.Load("TXTextControl.Web.MVC.DocumentViewer");
var builder = WebHost.CreateDefaultBuilder();
var app = builder
.UseKestrel(options => options.Listen(IPAddress.Parse("127.0.0.1"), 8888))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseWebRoot(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"))
.ConfigureServices((services) =>
{
services.AddCors();
services.AddMvc().AddMvcOptions(options =>
{
options.EnableEndpointRouting = false;
}).AddApplicationPart(assembly);
})
.Configure(app =>
{
app.UseHttpsRedirection();
app.UseRouting();
app.UseCors(builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
app.UseAuthorization();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot")),
RequestPath = ""
});
app.UseMvcWithDefaultRoute();
}).Build();
app.Run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment