ASP.NET Core MVC控制器在单独的程序集中 [英] ASP.NET Core MVC controllers in separate assembly

查看:113
本文介绍了ASP.NET Core MVC控制器在单独的程序集中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ASP.NET MVC Core RC-2.我有一个针对整个.NET框架的Web项目.在解决方案中,我还有一个单独的类库,也针对整个框架.

在类库中,我有一个控制器,标有route属性.我已经从Web项目中引用了类库.该程序集引用了nuget包Microsoft.AspNetCore.Mvc v. 1.0.0-rc2-final.

据我了解,该外部控制器将被自动发现,例如 http://www.strathweb.com/2015/04/asp-net-mvc-6-discovers-controllers/

但是,这对我不起作用-我浏览到了该路线的URL,但我得到了一个空白页,并且没有达到我的控制器断点.

有什么想法可以使它正常工作吗?

有趣的是,它似乎确实适用于针对.NET Core Framework的Web项目,它引用了也针对.NET Core的类库.但不适用于针对整个框架的Web项目,它引用标准的.NET类库.

注意:这是MVC Core,应该支持这种情况,而无需任何解决方案

我相信您在RC2中遇到了以下已知问题. https://github.com/aspnet/Mvc/issues/4674 (提到了解决方法在错误中)

此后此问题已得到修复,但仅在下一个版本中可用(除非您可以使用夜间版本)

I'm using ASP.NET MVC Core RC-2. I have a web project targeting the full .NET framework. I also have a separate class library in the solution, also targeting the full framework.

In the class library, I have a controller, marked with a route attribute. I have referenced the class library from the web project. This assembly references the nuget package Microsoft.AspNetCore.Mvc v. 1.0.0-rc2-final.

It was my understanding that this external controller would be discovered automatically, e.g. http://www.strathweb.com/2015/04/asp-net-mvc-6-discovers-controllers/

However this doesn't work for me- I browse to the URL of the route and I get a blank page and it doesn't hit my controller breakpoint.

Any ideas how to get this working?

Interestingly, it does seem to work for web projects targeting .NET Core Framework, referencing a class library also targeting .NET Core. But not for a web project targeting the full framework, referencing a standard .NET class library.

Note: this is MVC Core which is supposed to support this kind of scenario without any MVC<=4 routing overrides.

解决方案

I believe you are hitting the following known issue in RC2. https://github.com/aspnet/Mvc/issues/4674 (workaround is mentioned in the bug)

This has been fixed since then but will only be available in next release (unless you are ok with using nightly builds)

这篇关于ASP.NET Core MVC控制器在单独的程序集中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆