You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.0 KiB
70 lines
2.0 KiB
#if NET40 || NET461
|
|
|
|
// global.ashx
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Web;
|
|
using System.Web.Routing;
|
|
|
|
namespace Apewer.Web
|
|
{
|
|
|
|
/// <summary></summary>
|
|
public class WebsiteGlobal : HttpApplication
|
|
{
|
|
|
|
/// <summary></summary>
|
|
public WebsiteGlobal() { }
|
|
|
|
/// <summary></summary>
|
|
protected virtual void Application_Start(object sender, EventArgs e) { }
|
|
|
|
/// <summary></summary>
|
|
protected virtual void Application_End(object sender, EventArgs e) { }
|
|
|
|
/// <summary></summary>
|
|
protected virtual void Application_Error(object sender, EventArgs e) { }
|
|
|
|
/// <summary></summary>
|
|
protected virtual void Application_BeginRequest(object sender, EventArgs e) { }
|
|
|
|
/// <summary></summary>
|
|
protected virtual void Application_AuthenticateRequest(object sender, EventArgs e) { }
|
|
|
|
/// <summary></summary>
|
|
protected virtual void Session_Start(object sender, EventArgs e) { }
|
|
|
|
/// <summary></summary>
|
|
protected virtual void Session_End(object sender, EventArgs e) { }
|
|
|
|
/// <summary>路由处理所有请求(包括指向文件的请求),与定义的模式匹配的所有请求都由路由处理。</summary>
|
|
protected void AddRouter(bool value = true)
|
|
{
|
|
RouteTable.Routes.RouteExistingFiles = value;
|
|
}
|
|
|
|
/// <summary>添加路由。</summary>
|
|
protected void AddRouter(string url, string path)
|
|
{
|
|
if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(path)) return;
|
|
RouteTable.Routes.MapPageRoute("", url, path, false);
|
|
}
|
|
|
|
/// <summary>添加路由。</summary>
|
|
protected void AddRouter(Dictionary<string, string> 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
|
|
|