1Mayur
1Mayur

Reputation: 3485

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

Upvotes: 4

Views: 2479

Answers (2)

Dennis Traub
Dennis Traub

Reputation: 51634

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

Upvotes: 3

Jon Egerton
Jon Egerton

Reputation: 41559

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

Upvotes: 1

Related Questions