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.
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.
Post Details
- Posted
- 6 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/csharp/comm...