예제 #1
0
        private void ProcessDocument(XhtmlDocument document, ParameterList parameters)
        {
            string baseControllerUrl = GetBaseMvcRoute(parameters);

            ActionLinkHelper.ControllerLinksToC1PageLinks(document, baseControllerUrl);
        }
예제 #2
0
        private XhtmlDocument ExecuteRoute(RouteData routeData, ParameterList parameters, out bool routeResolved)
        {
            AttachDynamicDataUrlMappers();

            var parentContext = HttpContext.Current;

            using (var writer = new StringWriter())
            {
                var httpResponse   = new HttpResponse(writer);
                var httpContext    = new HttpContext(parentContext.Request, httpResponse);
                var requestContext = new RequestContext(new HttpContextWrapper(httpContext), routeData);

                CopyHttpContextData(parentContext, httpContext);

                var handler = routeData.RouteHandler.GetHttpHandler(requestContext);
                Verify.IsNotNull(handler, "No handler found for the function '{0}'", Namespace + "." + Name);

                try
                {
                    handler.ProcessRequest(httpContext);
                }
                catch (HttpException httpException)
                {
                    routeResolved = httpException.GetHttpCode() != 404;
                    throw;
                }
                catch (Exception ex)
                {
                    EmbedExceptionSourceCode(ex);
                    routeResolved = true;

                    throw;
                }

                string xhtml = writer.ToString();
                routeResolved = httpResponse.StatusCode != 404;

                if (!routeResolved)
                {
                    parentContext.Response.StatusCode = 404;
                    throw new HttpException((Int32)HttpStatusCode.NotFound, "Controller returns '404' http response code");
                }

                if (httpResponse.IsRequestBeingRedirected)
                {
                    string redirectUrl = httpResponse.RedirectLocation;
                    if (ActionLinkHelper.IsRawActionLink(redirectUrl))
                    {
                        redirectUrl = ActionLinkHelper.ConvertActionLink(redirectUrl, requestContext, _functionCollection.RouteCollection);
                        redirectUrl = ActionLinkHelper.ControllerLinkToC1PageLink(redirectUrl, GetBaseMvcRoute(parameters));
                    }

                    HttpContext.Current.Response.Redirect(redirectUrl, false);
                    return(null);
                }

                // TODO: Handle other HTTP Response Codes

                var document = ParseOutput(xhtml);
                ActionLinkHelper.ConvertActionLinks(document, requestContext, _functionCollection.RouteCollection);

                ProcessDocument(document, parameters);

                return(document);
            }
        }