private IHttpHandler GetAppPagesHandler(RequestContext requestContext, string virtualPath) { string pageName = requestContext.RouteData.GetRequiredString("page"); string[] urlSegments = requestContext.HttpContext.Request.Url.Segments; string folder = requestContext.RouteData.GetRequiredString("folder"); //urlSegments[urlSegments.Length - 2].Replace("/", ""); Screen screen = Screen.GetByFolderAndName(folder, pageName); if (screen != null) { ScreenType screenType = ScreenType.GetScreenType(screen); if (screenType == null) { throw new ApplicationException(String.Format("Screen type {0} could not be found in configuration", screen.Type)); } virtualPath = screenType.TemplateFile; } else { virtualPath = "~/Templates/Pages/PageNotFound.aspx"; } return((virtualPath != null) ? (IHttpHandler)BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(T)) : new T()); }