Giter Site home page Giter Site logo

multitenancyserver.aspnetcore's Issues

ITenancyContext returns null Tenant even when it's found in Store

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.