forked from Bremen/ESG
112 lines
2.8 KiB
C#
112 lines
2.8 KiB
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
//builder.Services.AddCors(options =>
|
|
//{
|
|
// options.AddDefaultPolicy(
|
|
// policy =>
|
|
// {
|
|
// policy.WithOrigins("http://www.bremen.com.tw",
|
|
// "http://bremen.com.tw",
|
|
// "https://www.bremen.com.tw",
|
|
// "https://bremen.com.tw",
|
|
// "http://preview.bremen.com.tw",
|
|
// "https://preview.bremen.com.tw"
|
|
// ).AllowAnyMethod().AllowAnyHeader();
|
|
// });
|
|
//});
|
|
|
|
//builder.Services.AddCors(options =>
|
|
//{
|
|
// options.AddDefaultPolicy(builder =>
|
|
// {
|
|
|
|
|
|
|
|
|
|
|
|
// builder
|
|
// .WithOrigins("https://*.bremen.com.tw",
|
|
// "https://localhost:7245",
|
|
// "https://bremen.com.tw")
|
|
// .AllowAnyMethod()
|
|
// .AllowAnyHeader();
|
|
|
|
|
|
// // builder
|
|
// //.WithOrigins(GlobalClass.appsettings("CorsOrigins")
|
|
// //.Split(",", StringSplitOptions.RemoveEmptyEntries)
|
|
// //.ToArray() ?? Array.Empty<string>())
|
|
// //.SetIsOriginAllowedToAllowWildcardSubdomains()
|
|
// //.AllowAnyMethod()
|
|
// //.AllowAnyHeader();
|
|
|
|
|
|
// });
|
|
//});
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddCors(options =>
|
|
{
|
|
options.AddPolicy(name: "any", builder =>
|
|
{
|
|
builder.WithOrigins("https://www.bremen.com.tw",
|
|
"https://bremen.com.tw", "https://preview.bremen.com.tw",
|
|
"http://970px.dscloud.me/")
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod();
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddControllersWithViews();
|
|
//builder.Services.AddControllers();
|
|
builder.Services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
app.UseExceptionHandler("/Home/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();
|
|
}
|
|
|
|
DefaultFilesOptions defaultFilesOptions = new DefaultFilesOptions();
|
|
defaultFilesOptions.DefaultFileNames.Clear();
|
|
defaultFilesOptions.DefaultFileNames.Add("index.html");
|
|
defaultFilesOptions.DefaultFileNames.Add("iisstart.htm");
|
|
app.UseDefaultFiles(defaultFilesOptions);
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
|
|
app.UseStaticFiles();
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseCors("any");
|
|
|
|
//app.UseAuthorization();
|
|
|
|
app.MapControllerRoute(
|
|
name: "default",
|
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
app.Run();
|