1. 首先在项目新建文件叫App_Code或者App_Start
在文件中新建WebFromRouteHandler.cs 文件。
WebFromRouteHandler中的代码如下,
public class WebFromRouteHandler : IRouteHandler{ public WebFromRouteHandler(string virtualPath) { this._VirtualPath = virtualPath; } private string _VirtualPath; public string VirtualPath { get { return _VirtualPath; } set { _VirtualPath = value; } } public IHttpHandler GetHttpHandler(RequestContext requestContext) { var page = BuildManager.CreateInstanceFromVirtualPath(VirtualPath, typeof(Page)) as IHttpHandler; return page; } } 2. Global.asax 中的代码如下:
public class Global : HttpApplication { void Application_Start(object sender, EventArgs e) { // 在应用程序启动时运行的代码 AuthConfig.RegisterOpenAuth(); RegisterRoutes(RouteTable.Routes); } void Application_End(object sender, EventArgs e) { // 在应用程序关闭时运行的代码 } void Application_Error(object sender, EventArgs e) { // 在出现未处理的错误时运行的代码 } public static void RegisterRoutes(RouteCollection routes) { routes.Add("Named", new Route("Named", new WebFromRouteHandler("/About.aspx"))); } }
3. 页面调用