Getting a domain from a subdomain

I get url like

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

I do not want to use string functions to use it to get the main domain, i.e.

mealsandyou.com

is there any function from C # for this, UrilAuthority and everything also gives a subdomain ...

Suggestions are welcome, not workarounds

+4
source share
2 answers

The only constant part of the domain string is the TLD. TLD is the last bit of a domain string, such as .com, .net, .uk, etc. Everything else under this depends on the specific TLD for its position (therefore, you cannot assume that the next last part is the โ€œdomain nameโ€ as for .co.uk it will be .co.

In any case, I think you're wrong. Rewriting URLs is much more suitable for this kind of thing. Read about it: learn.iis.net/page.aspx/460/using-the-url-rewrite-module

+1
source

.Net does not provide a built-in function for extracting specific parts from Uri.Host . You will have to use string manipulation or regular expression yourself.

+3
source

Source: https://habr.com/ru/post/1432220/


All Articles