Getting domain from subdomain

ε祈祈猫儿з 提交于 2019-12-30 23:16:34

问题


I get url as

http://orders.mealsandyou.com/default.php

i dont want to use string functions to use it to get the main domain ie

mealsandyou.com

is there any function in c# to do that, UrilAuthority and all gives subdomain too...

Suggestions welcome, not workarounds


回答1:


The only constant part of the domain string is the TLD. The TLD is the very last bit of the domain string, eg .com, .net, .uk etc. Everything else under that depends on the particular TLD for its position (so you can't assume the next to last part is the "domain name" as, for .co.uk it would be .co.

In any case I think you're taking the wrong approach. URL rewriting is far more suited to this sort of thing. Have a read of this: learn.iis.net/page.aspx/460/using-the-url-rewrite-module




回答2:


.Net doesn't provide a built-in feature to extract specific parts from Uri.Host. You will have to use string manipulation or a regular expression yourself.



来源:https://stackoverflow.com/questions/12259912/getting-domain-from-subdomain

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