Localhost and request.Url.Authority

ⅰ亾dé卋堺 提交于 2019-12-08 20:48:03

问题


My application separates users by company identifiers in the URL: company1.app.com, company2.app.com...

I am testing on my local PC with a request such as: company1.localhost.com. However, my request.Url.Authority still shows "localhost.com" instead of "company1.localhost.com". In fact, the prefix of 'company1' does not show anywhere. Is this a bug or a feature?

It's worth noting that I added to the host file an entry for "comapany.Blah -> 127.0.0.1". When looking at Request.Url.Authority it STIL shows localhost...


回答1:


Do not use the Authority, but use the Host

Request.Url.Host

The authority search back on dns, the host get the site from the url. When you search the dns you get the first name of your ip address that you have connected with that name and not all names.




回答2:


Use your headers on localhost:

Request.Headers.Get("Host")


来源:https://stackoverflow.com/questions/4299399/localhost-and-request-url-authority

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