6

While writing an asp.net project i may have this url for testing/debugging

http://localhost:1234/

I have code that takes in account of subdomains. Can i make visual studios call the same code with

http://anysub.localhost:1234/

1 Answers1

11

You can update your hosts file and put in any subdomin for the localhost:

127.0.0.1    example.com
127.0.0.1    sub.example.com

You can then point your browser to either domain. So long as the debugger is attached to IIS/Dev browser, you will be able debug your server side code.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • @sshow: It doesnt seem to work. I wrote `127.0.0.1 sub.localhost.com 127.0.0.1 *.localhost.com` in my host file. Saw it didnt work and restarted my computer. I get a `Server not found` error in firefox, chrome and IE8. I'm using windows 7 and only using VisualStudios. I dont know if thats consider IIS/Dev browser? –  Oct 28 '10 at 22:04
  • 1
    +1 also doing it like that here. @acidzombie24 try not using 'localhost' as the domain, not sure if it matters but that's a difference on how I'm using it. – eglasius Oct 28 '10 at 22:22
  • @eglasius: Wow, thanks eglasius. I used localdev.com and it worked perfectly. I just looked it up and wildcards arent possible. Thats so bad and now this answer is complete! accept and +1 –  Oct 28 '10 at 22:37
  • just wasted 2 hours googling, shoulda came to SO first..:) – stoic Jul 19 '11 at 17:07
  • @Oded, I'm using VS2015. I tried adding the above lines to the *hosts* file, but when I navigate to *example.com* or *sub.example.com*, I get an error and it doesn't try to access my website. – Shimmy Weitzhandler Aug 13 '15 at 19:04
  • 1
    What kind of error, @Shimmy? Do you put the name of your local website (instead of example.com)? Did you setup IIS for these with host names? – Oded Aug 13 '15 at 19:38
  • @Oded, I'm trying to utilize it in my local development machine using IIS Express. I added the 2 lines to the file as they are. – Shimmy Weitzhandler Aug 13 '15 at 19:43
  • 1
    @Shimmy - adding lines to the hosts file just tells your computer that `example.com` is the local computer. The browser will go to the local port 80 when you go to that URL. IIS needs to be running and the the port needs to be listening. Comments are really not a great place to troubleshoot this (in particular when not knowing the particulars of what you are doing). – Oded Aug 13 '15 at 19:46
  • @Oded, I'm sorry it's in the comments, but I don't think it deserves a question it will probably be blocked, my question is a 1:1 to the OP's question. I added those lines to the `hosts` file, when I navigate to `localhost:50963` it works just well. But if I go to `example.com:50963`, I get a 400 (bad request) error. – Shimmy Weitzhandler Aug 13 '15 at 23:11
  • @Shimmy - probably something on the IIS side then. You need to add `example.com` as a host header to the IIS site. – Oded Aug 14 '15 at 08:34
  • Do I have to add it manually one by one, or can I add `*.example.com` too? And can you please refer me to an article that shows how to configure the IIS? – Shimmy Weitzhandler Aug 14 '15 at 11:24
  • @Shimmy https://support.microsoft.com/en-us/kb/323972 - and that host header should be fine. – Oded Aug 14 '15 at 11:57