What's the best method in ASP.NET to obtain the current domain? -


i wondering best way obtain current domain in asp.net?

for instance:

http://www.domainname.com/subdir/ should yield http://www.domainname.com http://www.sub.domainname.com/subdir/ should yield http://sub.domainname.com

as guide, should able add url "/folder/content/filename.html" (say generated url.routeurl() in asp.net mvc) straight onto url , should work.

same answer mattmitchell's modification. checks default port instead.

request.url.scheme + system.uri.schemedelimiter + request.url.host + (request.url.isdefaultport ? "" : ":" + request.url.port) 

Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -