Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

5
.Net Core Multi Tenant using Area
Post Flair (click to view more posts with a particular flair)
Post Body

I am trying to setup a .net core web app that allows for tenants to create sub sites of their own. For example project1.website.com or project2.website.com. However I would like to have everything hosted from a single web app. I am wanting that when a user visits something like project1.website.com it than uses the the Area controllers and actions. I got something working with (based off this)

public override void OnActionExecuting(ActionExecutingContext actionExecutingContext) {
    var fullAddress = actionExecutingContext.HttpContext ? .Request ? .Headers ? ["Host"].ToString() ? .Split('.');
    if (fullAddress.Length > 2) {
        actionExecutingContext.Result = new StatusCodeResult(404);
        base.OnActionExecuting(actionExecutingContext);
    }
    else {
        var subdomain = fullAddress[0];
        var tenant = _dbContext.Tenants.SingleOrDefault(t = >string.Equals(t.Identifier, subdomain, StringComparison.OrdinalIgnoreCase));
        if (tenant != null) {
            actionExecutingContext.RouteData.Values.Add("Tenant", tenant);
            actionExecutingContext.RouteData.Values.Add("area", "Tenant");
            base.OnActionExecuting(actionExecutingContext);
        }
        else {
            actionExecutingContext.Result = new StatusCodeResult(404);
            base.OnActionExecuting(actionExecutingContext);
        }
    }
}

However it doesn't seem to actually use the Area/Tenant/Controllers/HomeController, when I add in break points they never get hit yet the page still loads for the Home/Index inside the area. Though if I manually enter the url of demo.website.com/home/index or home/test it breaks but does when typing in demo.website.com it does load the areas Home/Index.

I have gotten a site working with website.com/project1/Home/Index using the area but want to try to get it working using subdomains.

I have been searching on setting this up properly for a while now and every tutorial seems to be using some other method or not the same way I would like. Not even sure if something like this is possible but figure I would put it out there and ask.

Author
Account Strength
90%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
4,721
Link Karma
2,348
Comment Karma
2,373
Profile updated: 4 days ago
Posts updated: 4 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
6 years ago