2

I am developing an asp.net web site with Visual Studio 2012.

When I run the web application with Visual Studio, I use "http://localhost-si.mydomain.fr:65525"

When I do a debug, the property Request.Url return me "http://localhost:65525/default.aspx"

Why and how to get the full URL with the domain ("localhost-si.mydomain.fr" and not only "localhost") in Request.Url ?

Thank you very much for your help.

Yoann

biyoann
  • 21
  • 2
  • So, you have a subdomain registered under `mydomain.fr` called `localhost-si` for testing? If you are requesting your page via `http://mydomain.fr`, the `Request.Uri` should be just that. Likewise, if you are requesting the page locally from your own testing machine, the `Request.Uri` should be `http://localhost:65525`. What exactly are you asking? – Patrick Bell Apr 29 '16 at 13:23
  • @ext0 I think he has a hosts or DNS entry that points `localhost-si.mydomain.fr` to 127.0.0.1. Therefore, he would expect that the request URL would reflect how he had actually requested the page, rather than returning "localhost" (as he did not request the page on localhost) – RB. Apr 29 '16 at 13:26
  • @RB. Ah, I see, I'm not sure it's possible to get the original URI from that request then, since it's being routed through the local DNS first? – Patrick Bell Apr 29 '16 at 13:28
  • @biyoann What is the value of `request.Headers["Host"]`? This should be `localhost-si.mydomain.fr`. If it is, would this meet your requirements? – RB. Apr 29 '16 at 13:30
  • In order to do my local developpment of tests, I have to use a similar URL as my final web server. I changed my local host file to add the line 127.0.0.1 localhost-si.mydomain.fr The start page in my VisualStudio project is http://localhost-si.mydomain.fr:65525/ When I run the web application in debug mode, the site launches and although I go to page http://localhost-si.mydomain.fr:65525/default.aspx But when I set a breakpoint in my code, I have Request.Url = http://localhost:65525/default.aspx I want to recover my Request.Url = http://localhost-si.mydomain.fr:65525/default.aspx – biyoann Apr 29 '16 at 13:41
  • Possible duplicate of [Localhost and request.Url.Authority](http://stackoverflow.com/questions/4299399/localhost-and-request-url-authority) – RB. Apr 29 '16 at 13:56
  • Speaking from painful experience - do what you reasonably can so that your application doesn't depend on the domain of the request, or so that that detail is managed only at one point. I worked on an app where we switched from IIS to IIS express and now everything had a port number. It didn't change anything in production, but we had to make dozens of changes to account for that port number in development. Or weird redirects would depend on whether or now "www" was in the domain. – Scott Hannen Apr 29 '16 at 14:08

1 Answers1

1

In order to get the full domain name, I believe you will need to right click on your project and select Properties. There should be a web tab on the properties page that will allow you to specify the project url to use (note that I am looking at this with a newer version of Visual Studio, so it may look a bit different).

Note, however that you need to make sure that your local system can actually route that full domain name. If it cannot, you can edit your hosts file (easiest to do with a third party program like hostsman) to route http://localhost-si.mydomain.fr to 127.0.0.1.

mhagrelius
  • 21
  • 6
  • In order to do my local developpment of tests, I have to use a similar URL as my final web server. I changed my local host file to add the line 127.0.0.1 localhost-si.mydomain.fr The start page in my VisualStudio project is localhost-si.mydomain.fr:65525 When I run the web application in debug mode, the site launches and although I go to page localhost-si.mydomain.fr:65525/default.aspx But when I set a breakpoint in my code, I have Request.Url = localhost:65525/default.aspx I want to recover my Request.Url = localhost-si.mydomain.fr:65525/default.aspx – biyoann Apr 29 '16 at 13:43
  • It may required some additional tweaks like the ones noted in this question: [link](http://stackoverflow.com/questions/4709014/using-custom-domains-with-iis-express) – mhagrelius Apr 29 '16 at 16:16