In the same solution, there is a ASP.NET MVC4 application Slick.App
and class library Awesome.Mvc.Lib
. Awesome.Mvc.Lib contains one controller class.
public class ShinnyController : Controller
{
[HttpGet]
public string Index()
{
return "Hello, from Awesome.Mvc.Lib";
}
}
If I just add the reference from Slick.App to Awesome.Mvc.Lib, run the application and point brower to /shinny
, I will actually see the response "Hello, from Awesome.Mvc.Lib".
This is something I don't expect at all. All the time I thought ASP.NET MVC respects the namespaces there the controllers placed in. So, the controllers from another namespaces are not exposed, at least before I didn't ask to.
I tried to change the default route registration, to use namespaces parameter.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new [] { "Slick.App.Controllers" }
);
Still, the ShinnyController route still match for '/shinny'.
I have a concerns this is right default behaviour. My question is, how to explicitly say which controllers are exposed and prevent default route to match controllers in separate class library?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…