c# - How to get current domain name in ASP.NET -
c# - How to get current domain name in ASP.NET -
i want current domain name in asp.net c#.
i using code.
string domainname = httpcontext.current.request.url.host;
my url localhost:5858
but it's returning localhost
.
now, using project in localhost. want localhost:5858.
for example, when using domain
www.somedomainname.com
i want somedomainname.com
please give me thought how current domain name.
using request.url.host
appropriate - it's how retrieve value of http host:
header, specifies hostname (domain name) ua (browser) wants, resource-path part of http request not include hostname.
note localhost:5858
not domain name, endpoint specifier, known "authority", includes hostname , tcp port number. retrieved accessing request.uri.authority
.
furthermore, not valid somedomain.com
www.somedomain.com
because webserver configured serve different site www.somedomain.com
compared somedomain.com
, if sure valid in case you'll need manually parse hostname, though using string.split('.')
works in pinch.
note webserver (iis) configuration distinct asp.net's configuration, , asp.net ignorant of http binding configuration of websites , web-applications runs under. fact both iis , asp.net share same configuration files (web.config
) red-herring.
c# asp.net
Comments
Post a Comment