- 修正 admin 目錄預設頁路由,避免 403.14 與不必要的延遲重導 - 停用未使用的 Sites 多站點初始化,減少應用程式啟動成本 - 修正 Response.Redirect 後未 return 的流程,避免 1.8 分鐘超時 - 將資料庫 Connection Timeout 降為 10 秒,加速失敗回應 - 將 runAllManagedModulesForAllRequests 設為 false,讓 JS/CSS 等靜態檔案直接由 IIS 回應
68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Web.Http;
|
|
using System.IO;
|
|
using System.Web;
|
|
//using System.Web.Helpers;
|
|
using System.Web.Hosting;
|
|
using System.Net.Http.Headers;
|
|
using System.Threading.Tasks;
|
|
//using System.Web.Mvc;
|
|
|
|
|
|
[Route("files")]
|
|
public class FilesController : ApiController
|
|
{
|
|
// GET api/<controller>
|
|
public IEnumerable<string> Get()
|
|
{
|
|
return new string[] { "value1", "value2" };
|
|
}
|
|
|
|
[Route("upload/{*url}")]
|
|
public async Task<HttpResponseMessage> get_upload(string url)
|
|
{
|
|
// 改用標準路徑(原本使用 Sites 多站點功能,目前已停用)
|
|
var path = HttpContext.Current.Server.MapPath($"~/upload/{url}");
|
|
if (!System.IO.File.Exists(path))
|
|
{
|
|
throw new HttpResponseException(HttpStatusCode.NotFound);
|
|
}
|
|
string mimeType = MimeMapping.GetMimeMapping(path);
|
|
|
|
HttpResponseMessage response = new HttpResponseMessage();
|
|
response.Content = new StreamContent(new FileStream(path, FileMode.Open));
|
|
response.Content.Headers.ContentType = new MediaTypeHeaderValue(mimeType);
|
|
response.Headers.CacheControl = new CacheControlHeaderValue()
|
|
{
|
|
Public = true,
|
|
MaxAge = TimeSpan.FromSeconds(Sites.MaxAge) // MaxAge 常數仍可使用
|
|
};
|
|
|
|
return response;
|
|
}
|
|
[Route("public/{*url}")]
|
|
public string get_public (string url)
|
|
{
|
|
return "public:" + url;
|
|
}
|
|
|
|
// POST api/<controller>
|
|
public void Post([FromBody] string value)
|
|
{
|
|
}
|
|
|
|
// PUT api/<controller>/5
|
|
public void Put(int id, [FromBody] string value)
|
|
{
|
|
}
|
|
|
|
// DELETE api/<controller>/5
|
|
public void Delete(int id)
|
|
{
|
|
}
|
|
}
|