Tenant availability validation
I am using route strategy with in memory store.
I have added 2 tenants in the store tenant1 and tenant2 along with its connection string and all.
Now while opening page http://localhost/tenant1/Home/Index or http://localhost/tenant2/Home/Index. It is working fine as expected.
However, if I open http://localhost/tenant3/Home/Index, it is also opening however while database query it is failing as the tenant is not valid.
I have tried with the route strategy sample provided in the source, the issue is there also.
Am I missing something?
I would like to achieve that if the tenant is not available in the system should show 404 not found.

Hi @niravbhattsai
You aren't missing anything, in that case the request is being routed to the controller with no tenant detected, and in my view I decided to show the default page if no tenant was detected.
You could do something in your controller like this if you wanted to return a 404:
if(HttpContext.GetMultiTenantContext()?.TenantInfo == null)
return NotFound();
Maybe it would make for a good enhancement to somehow automatically return a 404 if the tenant isn't found when using the RouteStrategy.
Thanks @achandlerwhite, I am planning to use the similar approach.
I agree with you, it will be a good enhancement to return a 404. I did not get chance to look at the host strategy, but I believe it will be similar output.
In Host, if we map a CNAME record as * and in IIS we map *.domain.com, it is behaving same as route strategy.
@niravbhattsai I've pinned this issue as an enhancement so I can come back to it later. I'm glad you found a workaround for now-- let me know if you run into any problems.
Using this code everywhere can bore you. it looks better like this.
public class ActionFilterExample : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext context)
{
if (context.HttpContext.GetMultiTenantContext<TenantInfo>()?.TenantInfo == null)
context.Result = new BadRequestResult();
}
}
And
[ActionFilterExample]
public class HomeController : Controller