public static void Start()
        {
            // Even though ASP.NET will only call each PreAppStart once, we sometimes internally call one PreAppStart from
            // another PreAppStart to ensure that things get initialized in the right order. ASP.NET does not guarantee the
            // order so we have to guard against multiple calls.
            // All Start calls are made on same thread, so no lock needed here.

            if (_startWasCalled)
            {
                return;
            }
            _startWasCalled = true;

            // Summary of Simple Membership startup behavior:
            //  1. If the appSetting enabledSimpleMembership is present and equal to "false", NEITHER SimpleMembership NOR AutoFormsAuth are activated
            //  2. If the appSetting is true, a non-boolean string or not present, BOTH may be activated
            //    a. SimpleMembership ONLY replaces the AspNetSqlMemberhipProvider, but it does replace it even if it isn't the default.  This
            //       means that anything accessing this provider by name will get Simple Membership, but if this provider is no longer the default
            //       then SimpleMembership does not affect the default
            //    b. SimpleMembership delegates to the previous default provider UNLESS WebSecurity.InitializeDatabaseConnection is called.

            // Initialize membership provider
            WebSecurity.PreAppStartInit();

            // Initialize Forms Authentication default configuration
            SetUpFormsAuthentication();

            // Wire up WebMatrix.Data's Database object to the ASP.NET Web Pages resource tracker
            Database.ConnectionOpened += OnConnectionOpened;

            // Auto import the WebMatrix.Data and WebMatrix.WebData namespaces to all apps that are executing.
            WebPageRazorHost.AddGlobalImport("WebMatrix.Data");
            WebPageRazorHost.AddGlobalImport("WebMatrix.WebData");
        }
Exemple #2
0
        public static void Initialize()
        {
            WebPageRazorHost.AddGlobalImport("MvcSiteMapProvider.Web.Html");
            WebPageRazorHost.AddGlobalImport("MvcSiteMapProvider.Web.Html.Models");

            var settings = new ConfigurationSettings();

            if (settings.EnableSiteMapFile)
            {
                var validator = new SiteMapXmlValidator();
                validator.ValidateXml(HostingEnvironment.MapPath(settings.SiteMapFileName));
            }

            if (DependencyResolver.Current.GetType().FullName.Equals("System.Web.Mvc.DependencyResolver+DefaultDependencyResolver"))
            {
                var currentFactory = ControllerBuilder.Current.GetControllerFactory();
                ControllerBuilder.Current.SetControllerFactory(
                    new ControllerFactoryDecorator(currentFactory, settings));
            }
            else
            {
                var currentResolver = DependencyResolver.Current;
                DependencyResolver.SetResolver(new DependencyResolverDecorator(currentResolver, settings));
            }

            var siteMapLoaderContainer = new CustomSiteMapLoaderContainer(settings);

            SiteMaps.Loader = siteMapLoaderContainer.ResolveSiteMapLoader();

            if (settings.EnableSitemapsXml)
            {
                XmlSiteMapController.RegisterRoutes(RouteTable.Routes);
            }
        }
        /// <summary>
        /// Register global namepace imports for this assembly
        /// </summary>
        public static void Start()
        {
            WebPageRazorHost.AddGlobalImport("DotNetOpenAuth.AspNet");
            WebPageRazorHost.AddGlobalImport("Microsoft.Web.WebPages.OAuth");

            // Disable the "calls home" feature of DNOA
            DotNetOpenAuth.Reporting.Enabled = false;
        }
Exemple #4
0
        public static void Compose()
        {
#if !MVC2
            // Register global namespaces with Razor so we don't have to import them in Web.config
            WebPageRazorHost.AddGlobalImport("MvcSiteMapProvider.Web.Html");
            WebPageRazorHost.AddGlobalImport("MvcSiteMapProvider.Web.Html.Models");
#endif

            // Get the configuration settings
            var settings = new ConfigurationSettings();

            // If the config specifies to use an external DI container, skip the internal container.
            if (!settings.UseExternalDIContainer)
            {
                if (settings.EnableSiteMapFile)
                {
                    // Validate the Xml File.
                    var validator = new SiteMapXmlValidator();
                    validator.ValidateXml(HostingEnvironment.MapPath(settings.SiteMapFileName));
                }

#if !MVC2
                // If not using a custom DependencyResolver, we prefer to use IControllerFactory
                if (DependencyResolver.Current.GetType().FullName.Equals("System.Web.Mvc.DependencyResolver+DefaultDependencyResolver"))
                {
#endif
                // Setup the Controller Factory with a decorator that can resolve the internal controllers
                var currentFactory = ControllerBuilder.Current.GetControllerFactory();
                ControllerBuilder.Current.SetControllerFactory(
                    new ControllerFactoryDecorator(currentFactory, settings));
#if !MVC2
            }
            else
            {
                // If using a custom IDependencyResolver, decorate it with our IDependencyResolver so we can resolve
                // our internal controller.
                var currentResolver = DependencyResolver.Current;
                DependencyResolver.SetResolver(new DependencyResolverDecorator(currentResolver, settings));
            }
#endif

                // Set the static loader instance
                var siteMapLoaderContainer = new SiteMapLoaderContainer(settings);
                SiteMaps.Loader = siteMapLoaderContainer.ResolveSiteMapLoader();

                if (settings.EnableSitemapsXml)
                {
                    // Register the route for SiteMaps XML
                    XmlSiteMapController.RegisterRoutes(RouteTable.Routes);
                }
            }
        }
        public void PostProcessGeneratedCodeAddsGlobalImports()
        {
            // Arrange
            WebPageRazorHost.AddGlobalImport("Foo.Bar");
            CodeCompileUnit     generatedCode      = new CodeCompileUnit();
            CodeNamespace       generatedNamespace = new CodeNamespace();
            CodeTypeDeclaration generatedClass     = new CodeTypeDeclaration();
            CodeMemberMethod    executeMethod      = new CodeMemberMethod();
            WebPageRazorHost    host = new WebPageRazorHost("Foo.cshtml");

            // Act
            host.PostProcessGeneratedCode(generatedCode, generatedNamespace, generatedClass, executeMethod);

            // Assert
            Assert.IsTrue(generatedNamespace.Imports.OfType <CodeNamespaceImport>().Any(import => String.Equals("Foo.Bar", import.Namespace)));
        }
        public static void Start()
        {
            // Even though ASP.NET will only call each PreAppStart once, we sometimes internally call one PreAppStart from
            // another PreAppStart to ensure that things get initialized in the right order. ASP.NET does not guarantee the
            // order so we have to guard against multiple calls.
            // All Start calls are made on same thread, so no lock needed here.

            if (_startWasCalled)
            {
                return;
            }
            _startWasCalled = true;

            // Auto import the Microsoft.Web.Helpers namespace to all apps that are executing.
            WebPageRazorHost.AddGlobalImport(typeof(PreApplicationStartCode).Namespace);
        }
Exemple #7
0
        public static void Start()
        {
            if (_startCalled)
            {
                return;
            }
            _startCalled = true;

            var type = typeof(PreApplicationStartCode);

            // This is to make the precompiled web site work
            ApplicationPart.Register(new ApplicationPart(type.Assembly, @"~/sample"));

            // This is to make the precompiled helper work without an import.
            WebPageRazorHost.AddGlobalImport(type.Namespace);
        }
        public static void Start()
        {
            // Even though ASP.NET will only call each PreAppStart once, we sometimes internally call one PreAppStart from
            // another PreAppStart to ensure that things get initialized in the right order. ASP.NET does not guarantee the
            // order so we have to guard against multiple calls.
            // All Start calls are made on same thread, so no lock needed here.
            if (_startWasCalled)
            {
                return;
            }

            _startWasCalled = true;

            DynamicModuleUtility.RegisterModule(typeof(ImageOptimizationModule));

            WebPageRazorHost.AddGlobalImport(typeof(PreApplicationStartCode).Namespace);
        }
        public void PostProcessGeneratedCodeAddsGlobalImports()
        {
            // Arrange
            WebPageRazorHost.AddGlobalImport("Foo.Bar");
            WebPageRazorHost     host    = new WebPageRazorHost("Foo.cshtml");
            CodeGeneratorContext context = CodeGeneratorContext.Create(
                host,
                () => new CSharpCodeWriter(),
                "TestClass",
                "TestNs",
                "TestFile.cshtml",
                shouldGenerateLinePragmas: true);

            // Act
            host.PostProcessGeneratedCode(context);

            // Assert
            Assert.True(context.Namespace.Imports.OfType <CodeNamespaceImport>().Any(import => String.Equals("Foo.Bar", import.Namespace)));
        }