Mapping Subdomains to Areas in ASP.Net Core 3

半城伤御伤魂 提交于 2019-12-24 10:55:51

问题


What I want to achieve

  • Mapping my normal domain e.g.example.com to no area if possible.
  • Mapping my subdomain e.g. blog.example.com to a area named blog.

What I have found

There are actually quite a lot of posts regarding to this topic, especially mapping subdomains to areas.

From SO:

  • area-and-subdomain-routing
  • asp-net-core-mapping-subdomains-to-areas

Others:

  • danylkoweb.com
  • benjii.me
  • web.archive.org

And there are probably even more.

Problem

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.

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.

Additional information

  • I am using SDK 3.0.100-preview6-012264, but trying to upgrade to SDK 3.0.100-preview7-012821 as soon as possible.
  • I am using a reserve proxy (nginx) which passes the request to the ASP.Net Core Server.

回答1:


You said all requests pass on nginx but nothing said about nginx redirection, did you try to use nginx to do that, just redirect the sub-domain to domain using /etc/nginx/nginx.conf.

server {
   server_name sub.domain.co;
   location / {
   return 301 $scheme://domain.co/BlogSite$request_uri;
  }
}

(BlogSite is your area routing on ASP.Net Core Server.)



来源:https://stackoverflow.com/questions/57172884/mapping-subdomains-to-areas-in-asp-net-core-3

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