#if NET40 || NET461
// global.ashx
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Routing;
namespace Apewer.Web
{
///
public class WebsiteGlobal : HttpApplication
{
///
public WebsiteGlobal() { }
///
protected virtual void Application_Start(object sender, EventArgs e) { }
///
protected virtual void Application_End(object sender, EventArgs e) { }
///
protected virtual void Application_Error(object sender, EventArgs e) { }
///
protected virtual void Application_BeginRequest(object sender, EventArgs e) { }
///
protected virtual void Application_AuthenticateRequest(object sender, EventArgs e) { }
///
protected virtual void Session_Start(object sender, EventArgs e) { }
///
protected virtual void Session_End(object sender, EventArgs e) { }
/// 路由处理所有请求(包括指向文件的请求),与定义的模式匹配的所有请求都由路由处理。
protected void AddRouter(bool value = true)
{
RouteTable.Routes.RouteExistingFiles = value;
}
/// 添加路由。
protected void AddRouter(string url, string path)
{
if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(path)) return;
RouteTable.Routes.MapPageRoute("", url, path, false);
}
/// 添加路由。
protected void AddRouter(Dictionary rules)
{
// rules.Add("api", "~/api.aspx");
// rules.Add("{app}/{function}/{*args}", "~/app.aspx");
if (rules == null) return;
foreach (var rule in rules)
{
AddRouter(rule.Key, rule.Value);
}
}
}
}
#endif