multitenancyserver / multitenancyserver.aspnetcore Goto Github PK
View Code? Open in Web Editor NEWMultiTenancyServer ASP.NET Core library.
License: Apache License 2.0
MultiTenancyServer ASP.NET Core library.
License: Apache License 2.0
Hi! I'll start by congratulating you on this lib.
I'm trying to use this lib with an AspNetCore app to get multitenancy. Currently I already use other framework in my app to get modularization out of the box, it's the OrchardCore .
I'm not sure the behavior I'm discribing next is realy this lib problem, or maybe is somethign I'm doing wrong, but I'm not getting any clue why this happens when debugging. Maybe someone can help me with this.
This is a "standard" AspNetCore app, the Startup class is like this:
public void ConfigureServices(IServiceCollection services)
{
services.AddOrchardCore().AddMvc();
services.AddRazorPages();
services.AddDbContext<ApplicationDbContext>(options =>
{
options.UseSqlite(Configuration.GetConnectionString("ManagementConnection"));
});
services.AddMultiTenancy<ApplicationTenant, string>()
.AddSubdomainParser(".localhost")
.AddEntityFrameworkStore<ApplicationDbContext, ApplicationTenant, string>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
//app.UseAuthorization();
app.UseMultiTenancy<ApplicationTenant>();
//app.UseOrchardCore();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
}
Then with a Razor Page like this, I get the current Tenant:
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
private readonly ITenancyContext<ApplicationTenant> _tenancyContext;
public IndexModel(ILogger<IndexModel> logger, ITenancyContext<ApplicationTenant> tenancyContext)
{
_logger = logger;
_tenancyContext = tenancyContext;
}
public string Tenant { get; set; }
public void OnGet()
{
Tenant = _tenancyContext.Tenant?.CanonicalName ?? "-- Not Found --";
}
}
Everything is fine with this. The problem is when I had the line (uncomment the line in Startup class sample above)
app.UseOrchardCore();
This adds some middleware to the pipeline, and the behavior of ITenancyContext<ApplicationTenant>
changes, does not have value for the Tenant
property when it hits the razor page.
When debugging, I can see that the HttpTenancyProvider.GetCurrentTenantAsync
finds the correct tenant in the store, but when the code hits the razor page, the value is null.
I leave here the link to a repo where there is a sample app that reproduces this.
Hope someone can help me with this.
Best regards!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.