chore: 首次簽入 Thinkyu ASP.NET 專案
- 加入 Visual Studio / ASP.NET .gitignore - 排除建置輸出、IDE 設定、NuGet packages、大型 MSI 安裝檔
This commit is contained in:
@@ -0,0 +1,214 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.SessionState;
|
||||
using System.Configuration;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Web.Configuration;
|
||||
using WEB;
|
||||
using WebLib;
|
||||
|
||||
namespace Education
|
||||
{
|
||||
public class Global : System.Web.HttpApplication
|
||||
{
|
||||
protected void Application_Start(object sender, EventArgs e)
|
||||
{
|
||||
StringTable.Insert = false;
|
||||
StringTable.ByPass = true;
|
||||
|
||||
#region 讀進 Web.Config 中的系統參數
|
||||
|
||||
if (ConfigurationManager.AppSettings["ConnectionString"] != null)
|
||||
PublicVariable.ConnectionString = ConfigurationManager.ConnectionStrings[ConfigurationManager.AppSettings["ConnectionString"]].ConnectionString;
|
||||
else
|
||||
PublicVariable.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
|
||||
|
||||
DAC.ConnectionString = DAC.connTypeMSSQL;
|
||||
DAC.ConnectionString = PublicVariable.ConnectionString;
|
||||
|
||||
if (ConfigurationManager.AppSettings["UserLanguage"] != null)
|
||||
PublicVariable.UserLanguage = ConfigurationManager.AppSettings["UserLanguage"];
|
||||
|
||||
if (ConfigurationManager.AppSettings["CompanyName"] != null)
|
||||
PublicVariable.CompanyName = ConfigurationManager.AppSettings["CompanyName"];
|
||||
|
||||
if (ConfigurationManager.AppSettings["CopyrightText"] != null)
|
||||
PublicVariable.CopyrightText = ConfigurationManager.AppSettings["CopyrightText"];
|
||||
|
||||
if (ConfigurationManager.AppSettings["Theme"] != null)
|
||||
PublicVariable.Theme = ConfigurationManager.AppSettings["Theme"].ToLower();
|
||||
|
||||
if (ConfigurationManager.AppSettings["SystemName"] != null)
|
||||
PublicVariable.SystemName = ConfigurationManager.AppSettings["SystemName"].ToLower();
|
||||
|
||||
if (ConfigurationManager.AppSettings["NoLoginFunction"] != null)
|
||||
PublicVariable.NoLoginFunction = Convert.ToBoolean(ConfigurationManager.AppSettings["NoLoginFunction"].ToLower());
|
||||
|
||||
if (ConfigurationManager.AppSettings["總管理處ID"] != null)
|
||||
PublicVariable.總管理處ID = DAC.GetInt32(ConfigurationManager.AppSettings["總管理處ID"]);
|
||||
|
||||
if (ConfigurationManager.AppSettings["人資部ID"] != null)
|
||||
PublicVariable.人資部ID = DAC.GetInt32(ConfigurationManager.AppSettings["人資部ID"]);
|
||||
|
||||
if (ConfigurationManager.AppSettings["財務部ID"] != null)
|
||||
PublicVariable.財務部ID = DAC.GetInt32(ConfigurationManager.AppSettings["財務部ID"]);
|
||||
|
||||
#region 發郵件設定
|
||||
if (ConfigurationManager.AppSettings["SendMailBySSL"] != null)
|
||||
PublicVariable.SendMailBySSL = Convert.ToBoolean(ConfigurationManager.AppSettings["SendMailBySSL"].ToLower());
|
||||
|
||||
if (ConfigurationManager.AppSettings["SendMailHost"] != null)
|
||||
PublicVariable.SendMailHost = ConfigurationManager.AppSettings["SendMailHost"];
|
||||
|
||||
if (ConfigurationManager.AppSettings["SendMailPort"] != null)
|
||||
PublicVariable.SendMailPort = Convert.ToInt32(ConfigurationManager.AppSettings["SendMailPort"]);
|
||||
|
||||
if (ConfigurationManager.AppSettings["SendMailUserName"] != null)
|
||||
PublicVariable.SendMailUserName = ConfigurationManager.AppSettings["SendMailUserName"];
|
||||
|
||||
if (ConfigurationManager.AppSettings["SendMailPassword"] != null)
|
||||
PublicVariable.SendMailPassword = ConfigurationManager.AppSettings["SendMailPassword"];
|
||||
#endregion
|
||||
|
||||
#region 滿意度調查催填設定
|
||||
if (ConfigurationManager.AppSettings[PublicVariable.SurveyReminderDeadlineDaysKey] != null)
|
||||
PublicVariable.SurveyReminderDeadlineDays = Convert.ToInt32(ConfigurationManager.AppSettings[PublicVariable.SurveyReminderDeadlineDaysKey]);
|
||||
if (ConfigurationManager.AppSettings[PublicVariable.SurveyReminderExcludeEmployeesKey] != null)
|
||||
PublicVariable.SurveyReminderExcludeEmployees = ConfigurationManager.AppSettings[PublicVariable.SurveyReminderExcludeEmployeesKey];
|
||||
if (ConfigurationManager.AppSettings[PublicVariable.SurveyReminderMinCourseDateKey] != null)
|
||||
PublicVariable.SurveyReminderMinCourseDate = Convert.ToDateTime(ConfigurationManager.AppSettings[PublicVariable.SurveyReminderMinCourseDateKey]);
|
||||
if (ConfigurationManager.AppSettings[PublicVariable.SiteBaseUrlKey] != null)
|
||||
PublicVariable.SiteBaseUrl = ConfigurationManager.AppSettings[PublicVariable.SiteBaseUrlKey];
|
||||
#endregion
|
||||
|
||||
#region 設定相關服務的參數
|
||||
LookupList.LookupConfigCache = false;
|
||||
LookupList.LookupConfigFile = Server.MapPath("~/Config/LookupConfig.xml");
|
||||
|
||||
MailService.Host = PublicVariable.SendMailHost;
|
||||
MailService.Port = PublicVariable.SendMailPort;
|
||||
MailService.UserName = PublicVariable.SendMailUserName;
|
||||
MailService.Password = PublicVariable.SendMailPassword;
|
||||
MailService.UseSSL = PublicVariable.SendMailBySSL;
|
||||
MailService.LogPath = Server.MapPath("~/Log");
|
||||
MailService.UseDbAsQueue = true;
|
||||
MailService.Enabled = true;
|
||||
|
||||
DeleteFileService.DeletePatterns.Add(Server.MapPath("~/ReportData") + "/*.mdb");
|
||||
DeleteFileService.Enabled = true;
|
||||
|
||||
// 簽核跟催郵件
|
||||
FollowService.TemplatePath = Server.MapPath("~/Template");
|
||||
FollowService.DoWorkTime = "00:00";
|
||||
FollowService.Enabled = true;
|
||||
#endregion
|
||||
|
||||
#region 設定 DEBUG 模式
|
||||
CompilationSection section = ConfigurationManager.GetSection("system.web/compilation") as CompilationSection;
|
||||
PublicVariable.DEBUG = section.Debug;
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
protected void Session_Start(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected void Application_BeginRequest(object sender, EventArgs e)
|
||||
{
|
||||
HttpRuntimeSection section = (HttpRuntimeSection)ConfigurationManager.GetSection("system.web/httpRuntime");
|
||||
int maxFileSize = section.MaxRequestLength * 1024;
|
||||
if (Request.ContentLength > maxFileSize)
|
||||
{
|
||||
Server.ClearError();
|
||||
Response.Redirect("~/Forms/Common/FileTooLarge.aspx");
|
||||
}
|
||||
}
|
||||
|
||||
protected void Application_AuthenticateRequest(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private string Message1 = @"錯誤網頁:{0}
|
||||
錯誤類別:{1}
|
||||
錯誤來源:{2}
|
||||
錯誤訊息:{3}
|
||||
堆疊內容:
|
||||
{4}
|
||||
|
||||
";
|
||||
|
||||
private string Message2 = @"以上的錯誤發生的原因是:
|
||||
錯誤類別:{0}
|
||||
錯誤來源:{1}
|
||||
錯誤訊息:{2}
|
||||
堆疊內容:
|
||||
{3}
|
||||
|
||||
";
|
||||
protected void Application_Error(object sender, EventArgs e)
|
||||
{
|
||||
// 發生未處理錯誤時執行的程式碼
|
||||
string Message = "";
|
||||
Exception ex = Server.GetLastError();
|
||||
|
||||
if (ex == null)
|
||||
{
|
||||
Server.ClearError();
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果是 404,重導到 404 頁面
|
||||
if (ex is HttpException httpException && httpException.GetHttpCode() == 404)
|
||||
{
|
||||
Server.ClearError();
|
||||
Response.Redirect("~/Forms/404.aspx");
|
||||
return;
|
||||
}
|
||||
|
||||
Message += String.Format(Message1,
|
||||
Request.Path,
|
||||
ex.GetType().FullName,
|
||||
ex.Source,
|
||||
ex.Message,
|
||||
ex.StackTrace);
|
||||
|
||||
ex = ex.InnerException;
|
||||
while (ex != null)
|
||||
{
|
||||
Message += String.Format(Message2,
|
||||
ex.GetType().FullName,
|
||||
ex.Source,
|
||||
ex.Message,
|
||||
ex.StackTrace);
|
||||
ex = ex.InnerException;
|
||||
}
|
||||
|
||||
//寫入文字檔
|
||||
string fileName = DateTime.UtcNow.AddHours(8).ToString("yyyyMMdd_HHmmss");
|
||||
System.IO.File.AppendAllText(Server.MapPath(string.Format(@"~/Log/{0}.txt", fileName)), Message);
|
||||
|
||||
//清除Error
|
||||
Server.ClearError();
|
||||
|
||||
Response.Redirect(String.Format("~/Forms/500.aspx?errcode={0}", fileName));
|
||||
}
|
||||
|
||||
protected void Session_End(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected void Application_End(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user