本文整理汇总了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>();
}
示例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?}");
});
}
示例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>();
}
示例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?}",
示例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();
});
});
}
示例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}");
//.........这里部分代码省略.........
示例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;
//.........这里部分代码省略.........
示例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?}");
});
}