CompliationLock throws HttpException when registering areas for ASP.NET MVC unit tests

邮差的信 提交于 2019-12-02 13:13:30

For anyone else that followed the MVC Areas tutorials on MSDN, you will find an issue if you ever add unit tests to the web application you created.

It tells you to add AreaRegistration.RegisterAllAreas() to the RegisterRoutes method. Unfortunately, that is a static method that gets upset when called from unit tests.

Instead, register areas within Application_Start, right before the RegisterRoutes call you just modified. If you call RegisterRoutes first, UrlParameter.Optional appears to stop working in area routes (keeps working in non-area routes, though).

protected void Application_Start() {
        AreaRegistration.RegisterAllAreas();
        RegisterRoutes(RouteTable.Routes);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!