1
Answer

How do I get just the domain name from current user?

BLove

BLove

16y
4.4k
1
I need to know the exact the domain name that the user is requesting. I am currently using Request.ServerVariables["HTTP_HOST"] but doesn't give eactly what I need. For example, if the HTTP_HOST is:

www.mydomain.com
mydomain.com:8080
abc.mydomain.com
xyz.mydomain.com:5000

I need all these to return "mydomain.com". Also if the website is called with localhost or IP address, I need that returned without flaw either (such as localhost or 66.34.23.99). What's the best way to do this? I need to make sure the domain is only return since my application uses this info to differentiate different domain names pointing to the same web application. Any solid RegEx out there to do this or maybe something native to C#?
Answers (1)