2
我寫了一個自定義路由處理程序。因爲我在我的網站與控制器名稱相沖突的地區,我得到的錯誤:發現多個類型匹配控制器命名...如何在MVC3的自定義路由處理程序中指定命名空間?
我想我需要在我的處理程序中指定一個名稱空間,對吧?
我曾嘗試以下,其中沒有工作:
public class MyRouteHandler : MvcRouteHandler
{
protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
{
(... complicated DB lookups and "re-writing" of requestContext.RouteData.Values["controller"] ...)
// doesn't work
requestContext.RouteData.Values["namespaces"] = new[] { "Site.Contollers" };
// doesn't work
requestContext.RouteData.DataTokens.Add("namespaces", new[] { "Site.Contollers" });
// doesn't work
requestContext.RouteData.Values["namespaces"] = "Site.Contollers";
// doesn't work
requestContext.RouteData.DataTokens.Add("namespaces", "Site.Contollers");
(... snip ...)
return base.GetHttpHandler(requestContext);
}
}
什麼是正確的方法是什麼?
注意:因爲我的處理程序執行數據庫查找並根據結果選擇不同的控制器,所以我無法在我的Global.asax.cs文件中使用基本的MapRoute()方法(據我所知)。
只是檢查,你是否在將值添加到'DataTokens'後調用'base.GetHttpHandler'? –
是的,我是。我會將這添加到我的問題中。 – user1092572
您是否使用自定義控制器工廠?或默認的'BaseControllerFactory'? –