- 修正 admin 目錄預設頁路由,避免 403.14 與不必要的延遲重導 - 停用未使用的 Sites 多站點初始化,減少應用程式啟動成本 - 修正 Response.Redirect 後未 return 的流程,避免 1.8 分鐘超時 - 將資料庫 Connection Timeout 降為 10 秒,加速失敗回應 - 將 runAllManagedModulesForAllRequests 設為 false,讓 JS/CSS 等靜態檔案直接由 IIS 回應
88 lines
2.4 KiB
C#
88 lines
2.4 KiB
C#
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web;
|
|
|
|
/// <summary>
|
|
/// Summary description for Sites
|
|
/// </summary>
|
|
public static class Sites
|
|
{
|
|
public static List<Site> sites = new List<Site>();
|
|
public static SiteResource resource = new SiteResource();
|
|
private static string appurl
|
|
{
|
|
get
|
|
{
|
|
return HttpContext.Current.Server.MapPath("~");
|
|
}
|
|
}
|
|
private static string site_host
|
|
{
|
|
get
|
|
{
|
|
string host = HttpContext.Current.Request.Url.Host;
|
|
string r = "default";
|
|
var h = sites.FirstOrDefault(q=>q.url == host);
|
|
if (h != null) { r = h.folder; }
|
|
return r;
|
|
}
|
|
}
|
|
private static string site_root
|
|
{
|
|
get
|
|
{
|
|
string r = "";
|
|
r = appurl;
|
|
return HttpContext.Current.Server.MapPath("~");
|
|
}
|
|
}
|
|
public static double MaxAge = 3600 * 24 * 365;
|
|
static Sites()
|
|
{
|
|
// 多站點功能暫時停用,未來有需要再啟用
|
|
// 如需啟用,取消下方註解即可
|
|
/*
|
|
JObject o=get_jsonfile(@"sites\sites-config.json");
|
|
sites = o["sites"].ToObject<List<Site>>();
|
|
resource = o["resource"].ToObject<SiteResource>();
|
|
//resource.Add(new KeyValuePair<string, string>("assets", "assets"));
|
|
//resource.Add(new KeyValuePair<string, string>("config", "config"));
|
|
*/
|
|
}
|
|
private static JObject get_jsonfile(string jsonfile)
|
|
{
|
|
JObject o;
|
|
//string appurl = HttpContext.Current.Server.MapPath("~");
|
|
string path = Path.Combine(appurl, jsonfile);
|
|
o = JObject.Parse(File.ReadAllText(path));
|
|
return o;
|
|
}
|
|
public static string get_url(string path, string url)
|
|
{
|
|
string r="";
|
|
char s = Path.DirectorySeparatorChar;
|
|
url = url.Replace('/', s);
|
|
r = $@"{appurl}sites{s}{site_host}{s}{path}{s}{url}";
|
|
return r;
|
|
}
|
|
|
|
}
|
|
public class Site
|
|
{
|
|
public string url { get; set; }
|
|
public string folder { get; set; }
|
|
public string connection { get; set; }
|
|
public string title { get; set; }
|
|
}
|
|
public class SiteResource
|
|
{
|
|
public string assets { get; set; }
|
|
public string config { get; set; }
|
|
public string modules { get; set; }
|
|
public string upload { get; set; }
|
|
}
|