Dealing with unwanted port numbers on localhost when debugging in Visual Studio
- by Dan Bailiff
So when I'm trying to debug a project in Visual Studio, I'll often have 1 or more services that I need to call. These services are separate projects and I'll launch them in separate instances of VS. ASP dev server kindly launches them with temporary port numbers attached. This would be fine except for my programs are looking for an IP without a port attached. (Typically it's as simple as "localhost"!) I've coped by using web config settings and changing the xml to use the port number while debugging. This still doesn't always work and occasionally I'll still have to fudge it and insert port numbers as strings in code! UGH! Then I have to remember to undo all the port herding code before deployment...
I want to stop doing this:
string _strBaseURL = String.Format("http://{0}:2277", ConfigurationManager.AppSettings["myservice_ip"].ToString());
What is the best practice here? Am I doomed to port herding while debugging VS apps?