101 lines
3.5 KiB
Plaintext
101 lines
3.5 KiB
Plaintext
<%@ Application Language="C#" %>
|
|
<%@ Import Namespace="System.Web.Routing" %>
|
|
<%@ Import Namespace="System.Web.Http" %>
|
|
<%@ Import Namespace="System.Web.Optimization" %>
|
|
<%@ Import Namespace="System.Linq" %>
|
|
<%@ Import Namespace="System.Data" %>
|
|
<%@ Import Namespace="System.Web.Configuration" %>
|
|
<%@ Import Namespace="System.Web.Http.Dispatcher" %>
|
|
|
|
|
|
<script runat="server">
|
|
void Application_Start(object sender, EventArgs e)
|
|
{
|
|
// Code that runs on application startup
|
|
// run static constructor
|
|
System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(Sites).TypeHandle);
|
|
//註冊webapi
|
|
GlobalConfiguration.Configure(WebApiConfig.Register);
|
|
//GlobalConfiguration.Configuration.Services.Replace(
|
|
// typeof(IHttpControllerSelector),
|
|
// new NamespaceHttpControllerSelector(GlobalConfiguration.Configuration));
|
|
|
|
|
|
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling =
|
|
Newtonsoft.Json.ReferenceLoopHandling.Ignore;
|
|
GlobalConfiguration.Configuration.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter);
|
|
//GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
|
|
//註冊自訂路由
|
|
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
|
InitializeFNumberSerial();//啟動項目的時候查詢出信眾編號的最大值放在記憶體中
|
|
|
|
//bundle js、css
|
|
//BundleConfig.RegisterBundles(BundleTable.Bundles);
|
|
|
|
|
|
}
|
|
|
|
void Application_End(object sender, EventArgs e)
|
|
{
|
|
// Code that runs on application shutdown
|
|
|
|
}
|
|
void Application_Error(object sender, EventArgs e)
|
|
{
|
|
// Code that runs when an unhandled error occurs
|
|
|
|
}
|
|
void Session_Start(object sender, EventArgs e)
|
|
{
|
|
// Code that runs when a new session is started
|
|
|
|
}
|
|
void Session_End(object sender, EventArgs e)
|
|
{
|
|
// Code that runs when a session ends.
|
|
// Note: The Session_End event is raised only when the sessionstate mode
|
|
// is set to InProc in the Web.config file. If session mode is set to StateServer
|
|
// or SQLServer, the event is not raised.
|
|
|
|
}
|
|
protected void Application_PostAuthorizeRequest()
|
|
{
|
|
System.Web.HttpContext.Current.SetSessionStateBehavior(System.Web.SessionState.SessionStateBehavior.Required);
|
|
}
|
|
|
|
private void InitializeFNumberSerial()
|
|
{
|
|
try
|
|
{
|
|
using (var _db = new Model.ezEntities())
|
|
{
|
|
var maxFNumber = _db.followers
|
|
.Where(m =>
|
|
////m.IsDel == false && ////不確定是否新增欄位? 先註解
|
|
m.f_number.Length == 14 &&
|
|
(m.f_number.StartsWith("M") || m.f_number.StartsWith("F")))
|
|
.OrderByDescending(m => m.reg_time)
|
|
.Select(m => m.f_number)
|
|
.FirstOrDefault();
|
|
|
|
int nextSerial = 0;
|
|
if (!string.IsNullOrEmpty(maxFNumber))
|
|
{
|
|
try
|
|
{
|
|
var serialPart = maxFNumber.Substring(9, 5);
|
|
nextSerial = int.Parse(serialPart);
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
Application["FNumberSerial"] = nextSerial;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Application["FNumberSerial"] = 0;
|
|
}
|
|
}
|
|
</script>
|