|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
using Microsoft.Extensions.FileProviders;
|
|
|
|
using WebApiClient;
|
|
|
|
using System.Globalization;
|
|
|
|
using Microsoft.AspNetCore.Mvc.Razor;
|
|
|
|
using Microsoft.AspNetCore.Localization;
|
|
|
|
using AMESCoreStudio.Web.Code;
|
|
|
|
using Microsoft.AspNetCore.Http.Features;
|
|
|
|
|
|
|
|
namespace AMESCoreStudio.Web
|
|
|
|
{
|
|
|
|
public class Startup
|
|
|
|
{
|
|
|
|
public Startup(IConfiguration configuration)
|
|
|
|
{
|
|
|
|
Configuration = configuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
{
|
|
|
|
// �X�RJSON
|
|
|
|
services.AddControllers().AddNewtonsoftJson();
|
|
|
|
|
|
|
|
// FormPost�ƶq�W��
|
|
|
|
services.Configure<FormOptions>(options =>
|
|
|
|
{
|
|
|
|
options.ValueLengthLimit = 209715200;
|
|
|
|
options.ValueCountLimit = int.MaxValue;
|
|
|
|
});
|
|
|
|
|
|
|
|
// ModelBinding���ƤW��
|
|
|
|
services.AddMvc(options =>
|
|
|
|
{
|
|
|
|
options.MaxModelBindingCollectionSize = int.MaxValue;
|
|
|
|
});
|
|
|
|
|
|
|
|
services.AddMvc().AddMvcOptions(options =>
|
|
|
|
{
|
|
|
|
options.MaxModelValidationErrors = 999999;
|
|
|
|
});
|
|
|
|
|
|
|
|
var config = Configuration.Get<VirtualPathConfig>().VirtualPath;
|
|
|
|
var fileServerOptions = new List<FileServerOptions>();
|
|
|
|
if (config != null)
|
|
|
|
{
|
|
|
|
config.ForEach(f =>
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
fileServerOptions.Add(new FileServerOptions
|
|
|
|
{
|
|
|
|
FileProvider = new PhysicalFileProvider(@f.RealPath),
|
|
|
|
RequestPath = new PathString(f.RequestPath),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
catch { }
|
|
|
|
});
|
|
|
|
};
|
|
|
|
services.AddSingleton<IFileServerProvider>(new FileServerProvider(fileServerOptions));
|
|
|
|
|
|
|
|
// CORS�]�w
|
|
|
|
services.AddCors(options =>
|
|
|
|
options.AddPolicy("AMESPolicy",
|
|
|
|
p => p.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()));
|
|
|
|
|
|
|
|
|
|
|
|
services.AddLocalization(o =>
|
|
|
|
{
|
|
|
|
o.ResourcesPath = "Resources";
|
|
|
|
});
|
|
|
|
|
|
|
|
services.AddMvc()
|
|
|
|
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
|
|
|
|
.AddDataAnnotationsLocalization(options =>
|
|
|
|
{
|
|
|
|
options.DataAnnotationLocalizerProvider = (type, factory) => factory.Create(typeof(SharedResource));
|
|
|
|
});
|
|
|
|
|
|
|
|
services.AddControllersWithViews().AddRazorRuntimeCompilation();
|
|
|
|
|
|
|
|
// Session�]�w
|
|
|
|
services.AddSession();
|
|
|
|
|
|
|
|
// �v���]�w
|
|
|
|
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
|
|
|
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
|
|
|
|
{
|
|
|
|
options.LoginPath = new PathString("/Login/Index");
|
|
|
|
options.LogoutPath = new PathString("/Login/Logout");
|
|
|
|
options.AccessDeniedPath = new PathString("/Home/Error");
|
|
|
|
options.Cookie.Name = "_AMESCookie";
|
|
|
|
options.SlidingExpiration = true;
|
|
|
|
options.Cookie.HttpOnly = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
// HttpClient�]�w
|
|
|
|
var types = typeof(Startup).Assembly.GetTypes()
|
|
|
|
.Where(type => type.IsInterface
|
|
|
|
&& ((System.Reflection.TypeInfo)type).ImplementedInterfaces != null
|
|
|
|
&& type.GetInterfaces().Any(a => a.FullName == typeof(IHttpApi).FullName));
|
|
|
|
foreach (var type in types)
|
|
|
|
{
|
|
|
|
// �]�w�I�sAPI ����10����
|
|
|
|
services.AddHttpApi(type).ConfigureHttpClient(o => { o.Timeout = TimeSpan.FromMinutes(10); });
|
|
|
|
services.ConfigureHttpApi(type, o =>
|
|
|
|
{
|
|
|
|
o.HttpHost = new Uri(AppSetting.Setting.ApiUrl);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IFileServerProvider fileServerprovider)
|
|
|
|
{
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
app.UseExceptionHandler("/Home/Error");
|
|
|
|
app.UseHsts();
|
|
|
|
}
|
|
|
|
|
|
|
|
app.UseCors("AMESPolicy");
|
|
|
|
|
|
|
|
app.UseStaticFiles();
|
|
|
|
|
|
|
|
IList<CultureInfo> supportedCultures = new List<CultureInfo>
|
|
|
|
{
|
|
|
|
new CultureInfo("en-US"),
|
|
|
|
new CultureInfo("zh-CN"),
|
|
|
|
new CultureInfo("zh-TW")
|
|
|
|
};
|
|
|
|
|
|
|
|
app.UseRequestLocalization(new RequestLocalizationOptions
|
|
|
|
{
|
|
|
|
DefaultRequestCulture = new RequestCulture("en-US"),
|
|
|
|
SupportedCultures = supportedCultures,
|
|
|
|
SupportedUICultures = supportedCultures
|
|
|
|
});
|
|
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.UseAuthentication();
|
|
|
|
app.UseSession();
|
|
|
|
|
|
|
|
// VersionCode�]�w��
|
|
|
|
app.Use(async (context, next) =>
|
|
|
|
{
|
|
|
|
var currentVersion = Configuration["VersionCode"];
|
|
|
|
var webVersion = context.Request.Cookies["VersionCode"];
|
|
|
|
if (string.IsNullOrEmpty(context.Request.Cookies["VersionCode"]))
|
|
|
|
{
|
|
|
|
context.Response.Cookies.Append("VersionCode", currentVersion);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( webVersion != currentVersion)
|
|
|
|
{
|
|
|
|
context.Response.ContentType = "text/html; charset=utf-8";
|
|
|
|
await context.Response.WriteAsync("AMES�����w�g���s!!<br>1. �Х������Ҧ��w�g���}����������<br>2. �A���s���}AMES����");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
await next.Invoke();
|
|
|
|
});
|
|
|
|
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
{
|
|
|
|
endpoints.MapControllerRoute(
|
|
|
|
name: "default",
|
|
|
|
pattern: "{controller=Login}/{action=Index}/{id?}");
|
|
|
|
});
|
|
|
|
|
|
|
|
app.UseCookiePolicy();
|
|
|
|
|
|
|
|
// �ɮץؿ�
|
|
|
|
app.UseFileServerProvider(fileServerprovider);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|