动态注册每个域(多租户)的路由

| 可以在application_start之后注册路由吗?在我们的多租户应用程序中,客户正在创建自己的网站(www.domaina.com,www.domainb.com等),所有这些都指向我们的应用程序。客户可以定义他们想要其网站的页面。因此,我们可以在AppStart中注册所有相应的路由,但是如果客户添加了新路由,那么应用程序将如何知道要提供该URL?我尝试在BeginRequest中注册路由,但这似乎做得不好。 基本上,我需要根据进入应用程序的域而具有不同的路由。有人这样做吗?     
已邀请:
您可以创建自定义路线。
public class MyRoute : RouteBase
{
    private readonly RoutesRepository _routesRepository;

    public MyRoute(RoutesRepository routesRepo)
    {
        _routesRepository = routesRepo;
    }

    #region Overrides of RouteBase

    public override RouteData GetRouteData(HttpContextBase httpContext)
    {
        //Here you get all custom urls(that users have created) for current domain. Then try to match request url with urls from collection. If ok then create route and return it.
    }

    ...

    #endregion
}
另外的选择: 您可以向路由添加自定义约束。约束将检查当前域是否有权访问特定页面。     
您可以在运行时更改路由,但是一旦更改,对于使用同一应用程序的所有域,路由都是相同的。一种解决方案是对每个路由配置使用此应用程序的不同实例,然后可以根据实例特定的域名进行配置。     

要回复问题请先登录注册