/// <summary> /// 获取 HTML 处理程序 /// </summary> /// <param name="virtualPath">要处理的 HTML 文档的虚拟路径</param> /// <returns>HTML 处理程序</returns> protected virtual IHtmlHandler GetHandler(string virtualPath) { IHtmlHandler handler = null; if (RequestContext != null) { handler = RequestContext.RouteData.DataTokens[JumonyRequestRoute.HtmlHandlerToken] as IHtmlHandler; RequestContext.RouteData.DataTokens.Remove(JumonyRequestRoute.HtmlHandlerToken); } return(handler ?? HtmlHandlerProvider.GetHandler(virtualPath)); }
/// <summary> /// 渲染部分视图 /// </summary> /// <param name="context">当前 HTTP 请求上下文</param> /// <param name="virtualPath">部分视图的虚拟路径</param> /// <returns>渲染结果</returns> public static string RenderPartial(HttpContextBase context, string virtualPath) { var handler = HtmlHandlerProvider.GetHandler(virtualPath); if (handler == null) { return(HtmlServices.LoadContent(virtualPath).Content); } var partialHandler = new JumonyPartialHandler(); return(partialHandler.RenderPartial(context, virtualPath, handler)); }
/// <summary> /// 获取路由信息,将对请求进行 RequestMapping 的结果包装成路由信息 /// </summary> /// <param name="httpContext">当前 HTTP 请求上下文</param> /// <returns>路由信息</returns> public override RouteData GetRouteData(HttpContextBase httpContext) { var virtualPath = httpContext.Request.CurrentExecutionFilePath; if (!VirtualPathProvider.FileExists(virtualPath))//文件不存在时不路由 { return(null); } var handler = HtmlHandlerProvider.GetHandler(virtualPath); if (handler == null) { return(null); } var routeData = new RouteData(this, new JumonyRouteHandler()); routeData.Values[HtmlHandlerToken] = handler; return(routeData); }