ASP.NET核心路由和2个参考项目
我在现有解决方案中添加了第二个项目,并且正在遇到路由请求的问题。
当我最初添加第二个项目时,路由没有问题。
但是,我想在第二个项目中使用DB上下文。当我添加项目参考的时候,我的问题就会表现出来。
问题是我收到模棱两可的路由请求,因此我需要找到一种将请求区分开的方法,例如,向家庭控制器。
请注意,我使用属性路由。
我想出了一些解决方法:
- 将DB上下文复制到第二个项目中。这有明显的缺点,是最吸引人的解决方案,但它将起作用。
- 设置有一些区分前缀的路由,即“/proj2home”等。虽然原油,但这是最不可思议的,并且可以直接实现。它确实为第二个项目的每个URL都要求一个路线值,但我可以将鼻子握住。
- 我已经考虑过使用了中间件,但是看起来错误来自用户图()(尽管我不是100%),所以我不确定当时我能做什么。
有谁知道某种实现这一目标的建筑机制?
I've added a second project to an existing solution and am running into a bit of an issue with routing requests.
When I initially add the second project, there is no problem with routing.
However, I have a DB Context in the original project that I'd like to use from the second. It is when I add the project reference that my issue manifests.
The issue is that I am getting ambiguous routing requests, so I need to find a way to distinguish requests, for example, to the Home Controller.
Be advised, I use attribute routing.
I've come up with a few workarounds:
- Copy the DB Context into the second project. This has obvious shortcomings and is the least attractive solution, but it will work.
- Set up routes with some distinguishing prefix, i.e. "/proj2Home", etc. While crude, this is the least objectionable and is straight-forward to implement. It does mandate a route value for every Url of the second project but I could hold my nose on that.
- I've considered using Middleware but it looks like the error is coming from UseRouting() (although I'm not 100% on this) so I'm not sure what I can do at that point.
Does anyone know of some sort of build-in mechanism to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论