예제 #1
0
        public async Task RenderAsync(ViewContext context)
        {
            CompiledPage cpage = null;

            if (_scriptCache.ContainsKey(Path))
            {
                cpage = _scriptCache[Path];
                if (cpage.CompileTime < File.GetLastWriteTime(Path))
                {
                    cpage = null;
                }
            }
            if (cpage == null)
            {
                try
                {
                    cpage = aspHost.ProcessPageFromFile(Path);
                    _scriptCache[Path] = cpage;
                }
                catch (VBScriptCompilerException ex)
                {
                    AspHelper.RenderError(context, ex);
                    return;
                }
            }

            ScriptScope responseScope = aspHost.CreateScope();
            HttpContext httpContext   = context.HttpContext;

            responseScope.SetVariable("request", httpContext.RequestServices.GetService <IAspRequest>());
            responseScope.SetVariable("session", httpContext.RequestServices.GetService <IAspSession>());
            responseScope.SetVariable("application", httpContext.RequestServices.GetService <IAspApplication>());
            responseScope.SetVariable("writer", context.Writer);
            IAspResponse aspResponse = httpContext.RequestServices.GetService <IAspResponse>();

            responseScope.SetVariable("response", aspResponse);

            responseScope.SetVariable("model", context.ViewData.Model);
            responseScope.SetVariable("viewdata", context.ViewData);
            responseScope.SetVariable("viewbag", context.ViewBag);

            responseScope.SetVariable("literals", cpage.Literals);

            object o = cpage.Code.Execute(responseScope);

            aspResponse.Flush();
        }
예제 #2
0
        public void Render(ViewContext viewContext, TextWriter writer)
        {
            string pagePath = viewContext.HttpContext.Server.MapPath(this.ViewPath);

            CompiledPage cpage = null;

            if (_scriptCache.ContainsKey(pagePath))
            {
                cpage = _scriptCache[pagePath];
                //don't use it if updated
                if (cpage.CompileTime < File.GetLastWriteTime(pagePath))
                {
                    cpage = null;
                }
            }

            if (cpage == null)
            {
                try
                {
                    cpage = aspHost.ProcessPageFromFile(pagePath);
                    _scriptCache[pagePath] = cpage;
                }
                catch (VBScriptCompilerException ex)
                {
                    AspHelper.RenderError(writer, ex);
                    return;
                }
            }

            ScriptScope responseScope = aspHost.CreateScope();
            HttpContext context       = HttpContext.Current;

            responseScope.SetVariable("context", context);
            responseScope.SetVariable("request", context.Request);
            responseScope.SetVariable("session", context.Session);
            responseScope.SetVariable("server", context.Server);
            responseScope.SetVariable("application", context.Application);
            //responseScope.SetVariable("response", new AspResponse(context));

            responseScope.SetVariable("writer", writer);
            responseScope.SetVariable("response", writer);

            responseScope.SetVariable("viewcontext", viewContext);
            responseScope.SetVariable("tempdata", viewContext.TempData);

            ViewDataDictionary viewData = viewContext.ViewData;

            responseScope.SetVariable("viewdata", viewData);
            responseScope.SetVariable("model", viewData.Model);

            ViewDataContainer viewDataContainer = new ViewDataContainer(viewData);

            responseScope.SetVariable("ajax", new AjaxHelper(viewContext, viewDataContainer));
            responseScope.SetVariable("html", new HtmlHelper(viewContext, viewDataContainer));
            responseScope.SetVariable("url", new UrlHelper(viewContext.RequestContext));

            //responseScope.SetVariable("err", new Microsoft.VisualBasic.ErrObject());
            //Used to get the literals
            responseScope.SetVariable("literals", cpage.Literals);

            try
            {
                object o = cpage.Code.Execute(responseScope);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }