当前位置: 首页>>代码示例>>C#>>正文


C# IApplicationBuilder.UseMultitenancy方法代码示例

本文整理汇总了C#中IApplicationBuilder.UseMultitenancy方法的典型用法代码示例。如果您正苦于以下问题:C# IApplicationBuilder.UseMultitenancy方法的具体用法?C# IApplicationBuilder.UseMultitenancy怎么用?C# IApplicationBuilder.UseMultitenancy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IApplicationBuilder的用法示例。


在下文中一共展示了IApplicationBuilder.UseMultitenancy方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(LogLevel.Debug);
			
            app.Map(
                new PathString("/onboarding"),
                branch => branch.Run(async ctx =>
                {
                    await ctx.Response.WriteAsync("Onboarding");
                })
            );

            app.UseMultitenancy<AppTenant>();

            app.Use(async (ctx, next) =>
            {
                if (ctx.GetTenant<AppTenant>().Name == "Default")
                {
                    ctx.Response.Redirect("/onboarding");
                } else
                {
                    await next();
                }
            });

            app.UseMiddleware<LogTenantMiddleware>();
        }
开发者ID:rdefreitas,项目名称:saaskit,代码行数:28,代码来源:Startup.cs

示例2: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseDeveloperExceptionPage();

            app.UseStaticFiles();

            app.UseMultitenancy<AppTenant>();

            app.UsePerTenant<AppTenant>((ctx, builder) =>
            {
                builder.UseCookieAuthentication(new CookieAuthenticationOptions()
                {
                    AuthenticationScheme = "Cookies",
                    LoginPath = new PathString("/account/login"),
                    AccessDeniedPath = new PathString("/account/forbidden"),
                    AutomaticAuthenticate = true,
                    AutomaticChallenge = true,
                    CookieName = $"{ctx.Tenant.Id}.AspNet.Cookies"
                });

                // only register for google if ClientId and ClientSecret both exist
                var clientId = Configuration[$"{ctx.Tenant.Id}:GoogleClientId"];
                var clientSecret = Configuration[$"{ctx.Tenant.Id}:GoogleClientSecret"];

                if (!string.IsNullOrWhiteSpace(clientId) && !string.IsNullOrWhiteSpace(clientSecret))
                {
                    builder.UseGoogleAuthentication(new GoogleOptions()
                    {
                        AuthenticationScheme = "Google",
                        SignInScheme = "Cookies",

                        ClientId = clientId,
                        ClientSecret = clientSecret

                    });
                }
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
开发者ID:saaskit,项目名称:saaskit,代码行数:58,代码来源:Startup.cs

示例3: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.MinimumLevel = LogLevel.Debug;
            loggerFactory.AddConsole(LogLevel.Debug);

            app.UseIISPlatformHandler();
            app.UseMultitenancy<AppTenant>();

            app.UseMiddleware<LogTenantMiddleware>();
        }
开发者ID:yonglehou,项目名称:saaskit,代码行数:11,代码来源:Startup.cs

示例4: Configure


//.........这里部分代码省略.........
                //app.UseStatusCodePagesWithReExecute("/error/{0}");
                //app.UseStatusCodePagesWithReExecute("/error/{0}");
            }
            else
            {
                
                app.UseExceptionHandler("/Home/Error");

                // handle 404 and other non success
                //app.UseStatusCodePages();

                // app.UseStatusCodePages(context => context.HttpContext.Response.SendAsync("Handler, status code: " + context.HttpContext.Response.StatusCode, "text/plain"));
                // app.UseStatusCodePages("text/plain", "Response, status code: {0}");
                // app.UseStatusCodePagesWithRedirects("~/errors/{0}"); // PathBase relative
                // app.UseStatusCodePagesWithRedirects("/base/errors/{0}"); // Absolute
                // app.UseStatusCodePages(builder => builder.UseWelcomePage());
                //app.UseStatusCodePagesWithReExecute("/errors/{0}");
                //app.UseStatusCodePagesWithReExecute("/error/{0}");
            }

            // Add the platform handler to the request pipeline.
            //app.UseIISPlatformHandler();
            app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());

            //app.UseRuntimeInfoPage("/info");

            // Add static files to the request pipeline.
            app.UseStaticFiles();
            
            // the only thing we are using session for is Alerts
            app.UseSession();
            //app.UseInMemorySession(configure: s => s.IdleTimeout = TimeSpan.FromMinutes(20));

            app.UseMultitenancy<SiteSettings>();

            // this is in Startup.CloudscribeCore.cs
            app.UseCloudscribeCore(multiTenantOptions,Configuration);

            // it is very important that all authentication configuration be set before configuring mvc
            // ie if app.UseFacebookAuthentication(); was below app.UseMvc the facebook login button will not be shown

            
            // Add MVC to the request pipeline.
            app.UseMvc(routes =>
            {
                // Understanding ASP.NET Routing:

                // it is very important that routes are registered in the correct order. more specific routes must be registered first and 
                // less specific routes must be registered later. a request may match more than one route.

                // When a request comes in it is compared to routes in the route table and the first route it matches is used no matter if a 
                // better match exists. therefore if a less specific route is registered first it will catch requests that would have a better 
                // match with a more specific route that was registered later.

                // ie the default route is usually the least specific route and must be registered last

                // something like a route for a cms would likely need to be the default route added last especially if you are not going to use 
                // a controller segment in the route because without a controller segment the route is less specific


                // default route for folder sites must be second to last
                if (multiTenantOptions.Value.Mode == MultiTenantMode.FolderName)
                {
                    routes.MapRoute(
                    name: "folderdefault",
                    template: "{sitefolder}/{controller}/{action}/{id?}",
开发者ID:lespera,项目名称:cloudscribe,代码行数:67,代码来源:Startup.cs

示例5: Configure

        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
        {
            loggerFactory
                .WithFilter(new FilterLoggerSettings
                {
                    {"Microsoft", LogLevel.Information},
                    {"System", LogLevel.Information},
                    {"DoingGood", LogLevel.Debug}
                })
                .AddConsole()
                .AddDebug();

            app.Map("/_ah", sub =>
            {
                sub.Run(HealthCheck.Run);
            });

            app.UseDefaultFiles();

            app.UseMiddleware<ReverseProxySupportMiddleware>();
            app.UseMiddleware<RequestLoggerMiddleware>();
            app.UseProfiling();

            app.UseStaticFiles(new StaticFileOptions
            {
                OnPrepareResponse = context =>
                {
                    if (context.Context.Request.Path.StartsWithSegments(new PathString("/app")))
                    {
                        context.Context.Response.Headers["Cache-Control"] = "no-cache, no-store";
                        context.Context.Response.Headers["Pragma"] = "no-cache";
                        context.Context.Response.Headers["Expires"] = "-1";
                    }
                }
            });

            app.Map("/signup", SignUpMiddleware.CreateOrganization);

            app.UseMultitenancy<Organization>();

            app.UsePerTenant<Organization>((tenant, pipeline) => {
                pipeline.Map("/" + tenant.Tenant.Slug, subApp => {
                    subApp.ConfigureAuthentication();
                    subApp.UseMvc();
                });
            });
        }
开发者ID:HopeNB,项目名称:web,代码行数:47,代码来源:Startup.cs

示例6: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        // you can add things to this method signature and they will be injected as long as they were registered during 
        // ConfigureServices
        public void Configure(
            IApplicationBuilder app, 
            IHostingEnvironment env, 
            ILoggerFactory loggerFactory,
            IOptions<cloudscribe.Core.Models.MultiTenantOptions> multiTenantOptionsAccessor,
            IServiceProvider serviceProvider,
            IOptions<RequestLocalizationOptions> localizationOptionsAccessor
            ,cloudscribe.Logging.Web.ILogRepository logRepo
            )
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            ConfigureLogging(loggerFactory, serviceProvider, logRepo);
            
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                app.UseBrowserLink();
            }

            var storage = Configuration["DevOptions:DbPlatform"];
            
            switch (storage)
            {
                case "NoDb":
                    CoreNoDbStartup.InitializeDataAsync(app.ApplicationServices).Wait();

                    // you can use this hack to add clients and scopes into the db since
                    // there is currently no ui to do it
                    // you should not use this on the first run that actually creates the initial cloudscribe data
                    // you must wait until after that and then you can get the needed siteid from the database
                    // this will only run at startup time and only add data if no data exists for the given site.
                    // if you pass in an invalid siteid it will not fail, you will get data with a bad siteid
                    // make note of your siteid, don't use these, these are from my NoDb storage
                    // site1 05301194-da1d-43a8-9aa4-6c5f8959f37b
                    // site2 a9e2c249-90b4-4770-9e99-9702d89f73b6
                    // replace null with your siteid and run the app, then change it back to null since it can only be a one time task
                    string sId = null;

                    CloudscribeIdentityServerIntegrationNoDbStorage.InitializeDatabaseAsync(
                        app.ApplicationServices,
                        sId,
                        GetClients(),
                        GetScopes()
                        ).Wait();

                    break;

                case "ef":
                default:
                    // this creates ensures the database is created and initial data
                    CoreEFStartup.InitializeDatabaseAsync(app.ApplicationServices).Wait();

                    // this one is only needed if using cloudscribe Logging with EF as the logging storage
                    LoggingEFStartup.InitializeDatabaseAsync(app.ApplicationServices).Wait();

                    // you can use this hack to add clients and scopes into the db since
                    // there is currently no ui to do it
                    // you should not use this on the first run that actually creates the initial cloudscribe data
                    // you must wait until after that and then you can get the needed siteid from the database
                    // this will only run at startup time and only add data if no data exists for the given site.
                    // if you pass in an invalid siteid it will not fail, you will get data with a bad siteid
                    // make note of your siteid, don't use these, these are from my db
                    // site1 8f54733c-3f3a-4971-bb1f-8950cea42f1a
                    // site2 7c111db3-e270-497a-9a12-aed436c764c6
                    // replace null with your siteid and run the app, then change it back to null since it can only be a one time task
                    string siteId = null;

                    CloudscribeIdentityServerIntegrationEFCoreStorage.InitializeDatabaseAsync(
                        app.ApplicationServices,
                        siteId,
                        GetClients(),
                        GetScopes()
                        ).Wait();
                    
                    break;
            }

            app.UseForwardedHeaders();

            app.UseStaticFiles();
            
            app.UseSession();
            
            app.UseRequestLocalization(localizationOptionsAccessor.Value);

            app.UseMultitenancy<cloudscribe.Core.Models.SiteContext>();

            var multiTenantOptions = multiTenantOptionsAccessor.Value;

            app.UsePerTenant<cloudscribe.Core.Models.SiteContext>((ctx, builder) =>
            {
                // custom 404 and error page - this preserves the status code (ie 404)
                if(string.IsNullOrEmpty(ctx.Tenant.SiteFolderName))
                {
                    builder.UseStatusCodePagesWithReExecute("/Home/Error/{0}");
//.........这里部分代码省略.........
开发者ID:joeaudette,项目名称:cloudscribe,代码行数:101,代码来源:Startup.cs

示例7: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        // you can add things to this method signature and they will be injected as long as they were registered during 
        // ConfigureServices
        public void Configure(
            IApplicationBuilder app, 
            IHostingEnvironment env, 
            ILoggerFactory loggerFactory,
            IOptions<cloudscribe.Core.Models.MultiTenantOptions> multiTenantOptionsAccessor,
            IServiceProvider serviceProvider,
            IOptions<RequestLocalizationOptions> localizationOptionsAccessor
            )
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();
            var storage = Configuration["DevOptions:DbPlatform"];
            if(storage != "NoDb")
            {   
                ConfigureLogging(loggerFactory, serviceProvider);
            }
            
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                app.UseBrowserLink();
            }
            //else
            //{
            //    app.UseExceptionHandler("/Home/Error");
            //}
            
            app.UseStaticFiles();

            // custom 404 and error page - this preserves the status code (ie 404)
            app.UseStatusCodePagesWithReExecute("/Home/Error/{0}");

            app.UseSession();
            
            app.UseRequestLocalization(localizationOptionsAccessor.Value);

            app.UseMultitenancy<cloudscribe.Core.Models.SiteSettings>();

            //app.UseTenantContainers<SiteSettings>();
            var multiTenantOptions = multiTenantOptionsAccessor.Value;

            app.UsePerTenant<cloudscribe.Core.Models.SiteSettings>((ctx, builder) =>
            {
                var tenant = ctx.Tenant;

                var shouldUseFolder = !multiTenantOptions.UseRelatedSitesMode
                                        && multiTenantOptions.Mode == cloudscribe.Core.Models.MultiTenantMode.FolderName
                                        && tenant.SiteFolderName.Length > 0;
                
                var externalCookieOptions = SetupOtherCookies(
                    cloudscribe.Core.Identity.AuthenticationScheme.External,
                    multiTenantOptions.UseRelatedSitesMode,
                    tenant);
                builder.UseCookieAuthentication(externalCookieOptions);

                var twoFactorRememberMeCookieOptions = SetupOtherCookies(
                    cloudscribe.Core.Identity.AuthenticationScheme.TwoFactorRememberMe,
                    multiTenantOptions.UseRelatedSitesMode,
                    tenant);
                builder.UseCookieAuthentication(twoFactorRememberMeCookieOptions);

                var twoFactorUserIdCookie = SetupOtherCookies(
                    cloudscribe.Core.Identity.AuthenticationScheme.TwoFactorUserId,
                    multiTenantOptions.UseRelatedSitesMode,
                    tenant);
                builder.UseCookieAuthentication(twoFactorUserIdCookie);

                var cookieEvents = new CookieAuthenticationEvents();
                var logger = loggerFactory.CreateLogger<cloudscribe.Core.Identity.SiteAuthCookieValidator>();
                var cookieValidator = new cloudscribe.Core.Identity.SiteAuthCookieValidator(logger);
                var appCookieOptions = SetupAppCookie(
                    cookieEvents,
                    cookieValidator,
                    cloudscribe.Core.Identity.AuthenticationScheme.Application,
                    multiTenantOptions.UseRelatedSitesMode,
                    tenant
                    );
                builder.UseCookieAuthentication(appCookieOptions);

                //builder.UseForwardedHeaders();
                // known issue here is if a site is updated to populate the
                // social auth keys, it currently requires a restart so that the middleware gets registered
                // in order for it to work or for the social auth buttons to appear 
                builder.UseSocialAuth(ctx.Tenant, externalCookieOptions, shouldUseFolder);
                
            });

            

            UseMvc(app, multiTenantOptions.Mode == cloudscribe.Core.Models.MultiTenantMode.FolderName);
            
            switch (storage)
            {
                case "NoDb":
                    CoreNoDbStartup.InitializeDataAsync(app.ApplicationServices).Wait();
                    break;
//.........这里部分代码省略.........
开发者ID:ReinhardHsu,项目名称:cloudscribe,代码行数:101,代码来源:Startup.cs

示例8: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app, 
            IHostingEnvironment env, 
            ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");

               
            }

            app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());

            app.UseStaticFiles();

            app.UseMultitenancy<AppTenant>();
            app.UsePerTenant<AppTenant>((ctx, builder) =>
            {
                builder.UseCookieAuthentication(options =>
                {
                    options.AuthenticationScheme = ctx.Tenant.AuthenticationScheme;
                    options.LoginPath = new PathString("/account/login");
                    options.AccessDeniedPath = new PathString("/account/forbidden");
                    options.AutomaticAuthenticate = true;
                    options.AutomaticChallenge = true;
                    options.CookieName = $"{ctx.Tenant.Id}.application";
                    options.Events = new CookieAuthenticationEvents
                    {
                        OnValidatePrincipal = SecurityStampValidator.ValidatePrincipalAsync
                    };
                });

                
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
开发者ID:joeaudette,项目名称:cloudscribe.Web.SimpleAuth,代码行数:53,代码来源:Startup.cs


注:本文中的IApplicationBuilder.UseMultitenancy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。