0
我正在處理我的第二個多租戶MVC應用程序。我的第一個沒有使用子域名。相反,它使用具有租戶(clientportal)標識符的第一個參數的路由。使用子域路由進行身份驗證
Route route = new Route("{clientportal}/{controller}/{action}/{id}",
new RouteValueDictionary(new
{
controller = "ClientPortalHome",
action = "Index",
id = UrlParameter.Optional
}), new PortalRouteHandler());
這次,我需要使用實際的子域名。
Client1.mysite.com
Client2.mysite.com
要做到這一點,我實現了一個類似的子域的路由:
Is it possible to make an ASP.NET MVC route based on a subdomain?
我的問題是這樣的。哪裏是正確的位置來處理加載我的用戶和驗證請求?
Application_AuthenticateRequest在子域路由之前被觸發。這意味着當AuthenticateRequest執行時,我不知道該請求是用於哪個租戶。
也許我可以加載用戶並在子域路由代碼中驗證請求,但是這種味道是錯誤的。
我在這裏錯過了什麼?
我最終創建了一個使用懶惰屬性來容納我的用戶的WorkContext對象。你的解決方案也可以很好地工作。 –
rboarman
2012-05-13 16:42:59