简体   繁体   中英

Getting domain from subdomain

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

.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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM