将子域映射到ASP.Net Core 3中的区域 [英] Mapping Subdomains to Areas in ASP.Net Core 3
问题描述
- 尽可能将我的普通域(例如
example.com
)映射到任何区域. - 映射我的子域,例如
blog.example.com
转到名为blog
的区域.
- Mapping my normal domain e.g.
example.com
to no area if possible. - Mapping my subdomain e.g.
blog.example.com
to a area namedblog
.
实际上有很多关于该主题的文章,特别是将子域映射到区域.
There are actually quite a lot of posts regarding to this topic, especially mapping subdomains to areas.
从SO:
其他:
- danylkoweb.com
- benjii.me >
- 可能还有更多.
但是有一个大问题,在ASP.Net Core 3中,他们更改了很多内容,其中之一是常规的路由,请参见
But there is one big problem, in ASP.Net Core 3 they changed a lot of things, one of them being the routing in general, see mircosoft's devblog. Basically they changed it so everything should now be endpoints.
所有类,例如
MvcRouteHandler
和接口,例如至少从我的理解来看,IRouter
现在基本上已经过时了.过了一会儿,在GitHub仓库中四处搜寻和挖掘后,我找不到任何有用的东西.All the classes e.g.
MvcRouteHandler
and interfaces e.g.IRouter
are basically obsolete now, at least from my understanding. After a while googling around and diggin' in the GitHub repositories I couldn't find anything useful.- 我正在使用
SDK 3.0.100-preview6-012264
,但尝试升级到尽快SDK 3.0.100-preview7-012821
. - 我正在使用备用代理(nginx),它将请求传递给ASP.Net Core Server.
推荐答案
要对整个情况进行更新,随着.Net Core 3的发布,您现在可以使用
To give an update to this whole situation, with the release of .Net Core 3 you can now make use of the
RequireHost
method.这看起来类似于以下内容:
This would look something like the following:
app.UseEndpoints(endpoints => { endpoints.MapAreaControllerRoute( name: "Home", areaName: "Home", pattern: "{controller=Home}/{action=Index}") .RequireHost("localhost:5001", "sub.domain.com"); }
如果像示例中那样删除pattern参数中的
Area
,则可以实现该目标.它仍然有些骇人听闻,但干净得多.请注意,您必须在所有端点上放置一个RequireHost
,以获取正确的默认路由匹配.If you remove the
Area
in the pattern parameter, like in the example, you can achieve exactly that. It is still somewhat hacky, but a lot cleaner. Note, that you would have to put aRequireHost
on all of the endpoints in order to get proper default route matching.这篇关于将子域映射到ASP.Net Core 3中的区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 我正在使用