ASP.NET:如何获取没有任何子域的域名?
我一直在这里搜索,但我似乎找不到这个问题的答案。我很想知道是否有一种方法可以只提供 HttpContext.Current.Request.Url
中的主域?
示例:
http://www.example.com > example.com
http://test.example.com > example.com
http://example.com > example.com
提前致谢。
编辑
只是为了澄清一点。这仅用于我自己的域,不会用于现有的每个域。
目前我需要处理三个后缀。
- .com
- .ca
- .local
I've been searching here on SO but I can't seem to find the answer to this question. I'm having a heck of a time figuring out if there's a method that will give me just the main domain from the HttpContext.Current.Request.Url
?
Examples:
http://www.example.com > example.com
http://test.example.com > example.com
http://example.com > example.com
Thanks in advance.
Edit
just to clarify a bit. This is for use on my own domains only and not going to be used on every domain in existence.
There's currently three suffixes that I need to be able to deal with.
- .com
- .ca
- .local
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有关允许任意注册的后缀列表,请参阅此处。
找到该列表中完整域名的最长后缀,然后返回该后缀之前的最后一个
.
之后的所有内容。See here for a list of suffixes that allow arbitrary registrations.
Find the longest suffix of the full domain name in that list, then return everything after the last
.
before that suffix.获取顶级域的列表,并将每个域与该列表进行匹配,匹配后仅取 1 个单词。
(您可能需要添加一些对 .co 的支持。
等等...
Get a list of top level domains, and match every domain with that list, taking only 1 word after the match.
(you might need to add some support for .co.
ect...
这是我提出的想法。
@SLaks,我很想听听您对此的想法。
Here's the idea that I've come up with.
@SLaks, I'd love to here your thoughts on this.