Open Closed

{TENANCY_NAME}.mydomain.com #1230


0
vnetonline created

Dear Support

I have changed the "Website Root Address" to {TENANCY_NAME}.mydomain.com in Host Settings.

I have also setup the wildcard hostname on Azure *.mydomain.com.

When I navigate to the site http://www.mydomain.com i can see the front end website.

When i click on the login button, I get the following error

Server Error in '/' Application.

There is no tenant defined with name www

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: Abp.UI.UserFriendlyException: There is no tenant defined with name www

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[UserFriendlyException: There is no tenant defined with name www]

is this functionality normal, am i supposed to create a www tenant to access the back end?

Should i rename the default tenant to www?


31 Answer(s)
  • 0
    vnetonline created

    Can someone please answer this??

  • 0
    hikalkan created

    Hi,

    You could redirect www.yourdomain.com to yourdomain.com in your DNS settings to avoid such a subdomain problem.

    But, if you want to make it via code, it's easy: Open SubdomainTenancyNameFinder.cs in your solution and modify GetCurrentTenancyNameOrNull() method to return null if current subdomain is "www". You can do it just before "return values[0];". Example code:

    if (string.Equals(values[0], "www", StringComparison.InvariantCultureIgnoreCase))
                {
                    return null;
                }
    

    Thus, www.yourdomain.com will be used as host address.

  • 0
    vnetonline created

    Thanks for the above ... that works perfectly.

    However, When i type in {TENANCY_NAME}.mydomain.com. I would like to go directly to the login page. How can i implement this??

  • 0
    hikalkan created

    If you don't need to a frontend page, go to HomeController and redirect to the Application Controller's Index action (for SPA).

  • 0
    vnetonline created

    Thanks for the info, I was thinking that but I only want to redirect certain subdomains straight to the login page? What is the best way of implementing this?

  • 0
    hikalkan created

    So, you can check subdomain and decide to redirect or not. You can get it from HttpContext.Current.

  • 0
    trendline created

    As we know in aspnet core version, the WebSiteRootAddress already move to appsettings.json, if change the WebSiteRootAddress like {TENANCY_NAME}.mydomain.com, use subdomain visit the site, it cannot find the tenant, furthermore on the login page, the change tenant name link disappeared.

    If change the WebSiteRootAddress as www.mydomain.com, use subdomain visit the site, although it cannot find the tenant, but on the login page, the change tenant name link can update the tenant name, then login could redirect to tenant admin panel.

    Is the feature still works fine? It is difficult to find a specificed tenant by subdomain with this bug.

    Any suggestion?

  • 0
    ismcagdas created

    Hi,

    Which version of ABP do you use in your project ?

    Thanks.

  • 0
    trendline created

    Version 1.4.2

  • 0
    ismcagdas created

    Hi,

    Sorry, this is my mistake, I couldn't understand your explanation at the first time :).

    This is actually the expected behaviour. When you set website address to {TENANCY_NAME}.mydomain.com and visit a subdomain, the change tenant name link disappeared if we can find the tenant from subdomain.

    When you visit the www.mydomain.com, we cannot find the tenant and change tenant name link becomes visible.

    Are you having a problem realted to this ?

  • 0
    trendline created

    Yes, the behavior just like you said, on the UI the process is that.

    But, when I using tenant1.mydomain.com visit the site, in fact the application doesn't found the tenant, if using the user of the tenant sign in system then will failed.

    This is the issue that I encountered now.

  • 0
    ismcagdas created

    Hi,

    In ABP 1.4.2, this class (https://github.com/aspnetboilerplate/as ... ributer.cs) should solve tenant from domain name.

    Can you create a similar class, for example MyDomainTenantResolveContributer and add it to tenancy resolvers in your web module's PreInitialize method and write soem logs to see if it can find tenant or not.

    You should add your custom resolver as the first resolver, because there are some other resolvers added here https://github.com/aspnetboilerplate/as ... ule.cs#L36.

    Thanks.

  • 0
    ianmark89 created

    You can fix it by removing http// or https:// like this one "WebSiteRootAddress": "{TENANCY_NAME}.yourdomain.com"

  • 0
    trendline created

    Follow up your suggestion, it still cannot resolve the issue, your approach will lose the tenant, it will cause current tenant user cannot login.

    I think this is a bug, remove "http://" or "https://" already implemented in [https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.AspNetCore/AspNetCore/MultiTenancy/DomainTenantResolveContributer.cs])

    @ ismcagdas , What do you think?

  • 0
    ismcagdas created

    Hi @trendline,

    Can you send your project to info@aspnetzero.com ? I can create a subdomain environment in my local machine and test this case for you. It is hard to find the problem without debugging it.

  • 0
    trendline created

    Thanks, I already sent a mail to you, please check.

  • 0
    ismcagdas created

    Hi,

    We have found a bug related to this, see https://github.com/aspnetboilerplate/as ... ssues/1907. For now, you can remove http:// from your WebSiteRootAddress in appsettings.json.

    So you will have something like

    "App": {
        "WebSiteRootAddress": "{TENANCY_NAME}.mydomain.com"
      },
    

    When we release new version of ABP, you can convert it back if you like.

  • 0
    cangunaydin created

    I am having this problem too. But changing it to {TENANCY_NAME}.mydomain.com isn't solved the problem do you have any idea about this?

  • 0
    ismcagdas created

    Hi,

    You problem is a bit different because in angular2 app's host project uses this address for CORS policy. I have replied your question as well.

  • 0
    trendline created

    After applied this https://github.com/aspnetboilerplate/as ... ssues/1907 fix, it still cannot resolve my issue that I mentioned before, it is strange sometimes it could find the tenant, sometimes it cannot find the tenant, sometimes it will use host user information instead of the expected Tenant.

    Could you have a look again?

  • 0
    ismcagdas created

    Hi,

    Can you share the configuration values for your application ? Like, website root address values.

  • 0
    trendline created

    the configuration in my appsettings.json file like below:

    "App": { "WebSiteRootAddress": "http://{TENANCY_NAME}.mydomain.com/" },

  • 0
    ismcagdas created

    Hi,

    Do you use any https addresses in your app ? If not, do you have an example address for your below comment ?

    it is strange sometimes it could find the tenant, sometimes it cannot find the tenant
    
  • 0
    trendline created

    No HTTPS enable.

    I will send you the demo URL via email.

  • 0
    ismcagdas created

    Hi,

    Thanks, I have replied your email.

  • 0
    trendline created

    I have created a similar class like DomainTenantResolverContributor and add the resolver in the Web Module in the MVC project, but when debug it the HttpContext is null

    var httpContext = _httpContextAccessor.HttpContext;
                if (httpContext == null)
                {
                    return null;
                }
    

    Did you get the similar exception before?

  • 0
    ismcagdas created

    Hi,

    We didn't get a similar exception before but we helped a customer recently for subdomain problem with angular2 project. I think you might have the same case.

    The problem was the / character at the end of WebSiteRootAddress value in host project's config. So you need to use a config like this.

    "WebSiteRootAddress": "http://{TENANCY_NAME}.mydomain.com"
    

    Dont put a / at the end of WebSiteRootAddress value.

    For DomainTenantResolveContributor, are you adding it in PreInitialize method of your module ?

    Thanks.

  • 0
    trendline created

    Yes, I put it in the PreInitialize method of Web Module in MVC project, but not remove "/" at the end of the WebSiteRootAddress, when debug it on dev machine sometimes it throw HttpContext is null.

    But, I deployed this changes to production, it works as expected, really a little strange. I also extended some customized code to match a customized Host per tenant, code like below:

    //Find independency hosts
                var tenants = from t in _tenantRepository.GetAllList()
                              select t;
    
                string[] hosts = null;
                foreach (var item in tenants)
                {
                    if (!item.Hosts.IsNullOrEmpty())
                    {
                        if (!item.Hosts.Contains(","))
                        {
                            hosts = new string[1];
                            hosts[0] = item.Hosts;
                        }
                        else
                        {
                            hosts = item.Hosts.Split(',').Length > 0 ? item.Hosts.Split(',') : null;
                        }
                        if (hosts.Count() > 0)
                        {
                            foreach (var host in hosts)
                            {
                                if (host.ToLower() == domainFormat.ToLower())
                                {
                                    Logger.Info("TenancyName:" + item.TenancyName);
                                    return item.Id;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                    }
                }
    

    Is the DomainTenantResolverContributor check each request? If that, I need to cache the tenant results from repository.

  • 0
    ismcagdas created

    Hi,

    Is the DomainTenantResolverContributor check each request?

    Yes, you can use ITenantStore as we did in DomainTenantResolverContributor.

  • 0
    chauey created

    I hosted Core API on service.abc.com without wildcard and Angular App hosted on {Tenant_Name}.abc.com with wildcard.

    As per your provided configuration, Tenant name is also include in "ServerRootAddress": "http://{TENANCY_NAME}.service.abc.com"

    do we also need wildcard for the Core API ?

    Please give me the solution for this I have only on wildcard and IP server, how can i implement multi tenancy ?

  • 0
    ismcagdas created

    Hi,

    We don't have much information on this. Since you are using a second level subdomain, it is better to ask this to a SSL certificate provider. I think they can give you a better answer.

    Thanks.