private void CreateContext(IHttpContext httpContext, string portalPath, string virtualPath, bool isPortalRoute) { foreach (VirtualResourcesElement resource in config.VirtualResources) { SetVirtualResourceData(resource.Name, new VirtualResourceData(resource.Namespace, resource.Assembly)); } PortalRequest request = CreateRequest(httpContext, portalPath, virtualPath, isPortalRoute); PortalResponse response = new PortalResponse(this); Request = request; Response = response; AddConfigOptions(this, request); if (isPortalRoute) { int firstSlashIndex = portalPath.IndexOf('/', 1); int length = firstSlashIndex >= 0 ? firstSlashIndex : portalPath.Length; request.TenantName = TenantCache.GetTenantName(httpContext.Request.Url.Host); if (!Compare.IsNullOrEmpty(request.TenantName)) { request.VirtualPath = "/Tenants/" + request.TenantName + request.VirtualPath; } Section = TenantCache.GetSectionOrDefault(request.TenantName, portalPath.Length == 1 ? null : portalPath.Substring(1, length - 1)); AddRouteContext(request, response, Section); AddControllerResult(this, request, Section); } PortalTrace.Write("PortalRequestModule", "CreateContext", "PortalContext created."); PortalTrace.Write("PortalRequestModule", "CreateContext", "Setup={0}, AllowPhysicalPages={1}, jQuery Version={2}", config.Setup, config.Routes.AllowPhysicalPages, config.JQuery.Version); }
private IHttpHandler GetPortalHandler(HttpContext context, string requestType, string virtualPath, string path) { IHttpHandler handler = base.GetHandler(context, requestType, virtualPath, path); PortalTrace.Write("PortalViewFactory", "GetHandler", "End base.GetHandler"); PortalView view = handler as PortalView; PortalTrace.WriteIf(view == null, "PortalViewFactory", "GetHandler", "'{0}' is not a portal view. Skipping initialization.", virtualPath); if (view != null) { PortalTrace.Write("PortalViewFactory", "GetHandler", "Initializing portal view for '{0}'", virtualPath); InitializeView(view); } return(handler); }
private void BeginRequest(HttpContext app) { PushObject(this); HttpContext = new WrappedHttpContext(app); string currentExecutionFilePath = HttpContext.Request.CurrentExecutionFilePath; bool isPortalRoute = !Path.HasExtension(currentExecutionFilePath); string virtualPath; string portalPath; int appPathLength = HttpContext.Request.ApplicationPath.Length; if (isPortalRoute) { if (currentExecutionFilePath.Length > 1 && currentExecutionFilePath.EndsWith("/")) { HttpContext.Response.RedirectPermanent(currentExecutionFilePath.TrimEnd('/')); } virtualPath = VirtualPathUtility.AppendTrailingSlash(currentExecutionFilePath) + RoutePathProvider.VirtualPageName; portalPath = appPathLength > 1 ? currentExecutionFilePath.Substring(appPathLength) : currentExecutionFilePath; if (Compare.IsNullOrEmpty(portalPath)) { portalPath = RootPath; } } else { virtualPath = currentExecutionFilePath; portalPath = appPathLength > 1 ? virtualPath.Substring(appPathLength) : virtualPath; } CreateContext(HttpContext, portalPath, virtualPath, isPortalRoute); if (!Request.IsPortalRoute || Request.Result == null) { return; } PortalTrace.Write("PortalRequestModule", "OnBeginRequest", "Rewriting portal path '{0}' to '{1}'.", Request.Path, Request.VirtualPath); HttpContext.RewritePath(Request.VirtualPath); }
private static void AddRouteContext(PortalRequest request, PortalResponse response, SectionData section) { PortalTrace.Write("PortalRequestModule", "InitializeRouteContext", "Begin InitializeRouteContext."); if (section == null) { throw new InvalidOperationException("No section found."); } List <Route> routes = section.GetMatchedRoutes(request.Path); if (routes.Count > 0) { AddRouteData(request, response, routes[0]); } PortalTrace.Write("PortalRequestModule", "InitializeRouteContext", "End InitializeRouteContext."); }
private void AuthorizeRequest() { //TODO: Handle null Request.Result PortalTrace.Warn("PortalContext", "BeginRequest", "Request.Result is null."); if (Request.Result == null) { //#if (!DEBUG) return; //throw new HttpException(404, null); } //#else //#endif if (Request.IsPortalRoute && !(Request.Result is IViewResult)) { Request.Result.Execute(new ControllerContext(this)); } }
/// <summary> /// Returns an instance of the <see cref="System.Web.IHttpHandler" /> interface to /// process the requested resource. /// </summary> /// <returns> /// A new <see cref="System.Web.IHttpHandler" /> that processes the request; otherwise, null. /// </returns> /// <param name="context"> /// An instance of the <see cref="System.Web.HttpContext" /> class /// that provides references to intrinsic server objects (for example, Request, Response, /// Session, and Server) used to service HTTP requests. /// </param> /// <param name="requestType"> /// The /// HTTP data transfer method (GET or POST) that the client uses. /// </param> /// <param name="virtualPath"> /// The /// virtual path to the requested resource. /// </param> /// <param name="path"> /// The /// <see cref="System.Web.HttpRequest.PhysicalApplicationPath" /> property to the requested /// resource. /// </param> public override IHttpHandler GetHandler(HttpContext context, string requestType, string virtualPath, string path) { PortalTrace.Write("PortalViewFactory", "GetHandler", "Begin base.GetHandler"); return(GetPortalHandler(context, requestType, virtualPath, path)); }