GetCompiledType() static private method

static private GetCompiledType ( TextReader reader, int inputHashCode, HttpContext context ) : Type
reader System.IO.TextReader
inputHashCode int
context HttpContext
return System.Type
Example #1
0
        /*
         * Compile an .ascx file into a UserControl derived Type
         */
        internal static Type GetCompiledUserControlType(string virtualPath,
                                                        string inputFile, HttpContext context)
        {
            CheckUserControlFileExtension(virtualPath);

            // We need unrestricted permission to process the UserControl file
            InternalSecurityPermissions.Unrestricted.Assert();

            UserControlParser parser = new UserControlParser();

            Type t = null;

            // Suspend client impersonation (for compilation)
            HttpContext.ImpersonationSuspendContext ictx = context.Impersonation.SuspendIfClient();

            try {
                try {
                    t = parser.GetCompiledType(virtualPath, inputFile, context);
                }
                finally {
                    // Resume client impersonation
                    ictx.Resume();
                }
            }
            catch { throw; } // Prevent Exception Filter Security Issue (ASURT 122835)

            return(t);
        }
Example #2
0
        Type GetTypeFromControlPath(string virtualPath)
        {
            if (virtualPath == null)
            {
                throw new ArgumentNullException("virtualPath");
            }

            string vpath = UrlUtils.Combine(TemplateSourceDirectory, virtualPath);

#if NET_2_0
            return(BuildManager.GetCompiledType(vpath));
#else
            string realpath = Context.Request.MapPath(vpath);
            return(UserControlParser.GetCompiledType(vpath, realpath, Context));
#endif
        }
Example #3
0
        public Control ParseControl(string content)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

#if NET_2_0
            // FIXME: This method needs to be rewritten in some sane way - the way it is now,
            // is a kludge. New version should not use
            // UserControlParser.GetCompiledType, but instead resort to some other way
            // of creating the content (template instantiation? BuildManager? TBD)
            TextReader reader  = new StringReader(content);
            Type       control = UserControlParser.GetCompiledType(reader, content.GetHashCode(), HttpContext.Current);
            if (control == null)
            {
                return(null);
            }

            TemplateControl parsedControl = Activator.CreateInstance(control, null) as TemplateControl;
            if (parsedControl == null)
            {
                return(null);
            }

            if (this is System.Web.UI.Page)
            {
                parsedControl.Page = (System.Web.UI.Page) this;
            }
            parsedControl.FrameworkInitialize();

            Control   ret   = new Control();
            int       count = parsedControl.Controls.Count;
            Control[] parsedControlControls = new Control [count];
            parsedControl.Controls.CopyTo(parsedControlControls, 0);

            for (int i = 0; i < count; i++)
            {
                ret.Controls.Add(parsedControlControls [i]);
            }

            parsedControl = null;
            return(ret);
#else
            return(null);
#endif
        }