<分区>
我已经编写了一个自定义路由处理程序。因为我的网站中有 Controller 名称冲突的区域,所以我收到错误消息:发现多个类型与名为...的 Controller 相匹配
我想我需要在我的处理程序中指定一个命名空间,对吧?
我尝试了以下方法,但均无效:
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);
}
}
正确的做法是什么?
注意:因为我的处理程序执行数据库查找并根据结果选择不同的 Controller ,所以我不能在我的 Global.asax.cs 文件中使用基本的 MapRoute() 方法(据我所知)。