Visual Studio: Debugging non localhost domain, locally - visual-studio

I have an entry in my hosts file that points somesite.com to 127.0.0.1 (localhost) so that I can test certain aspects of my web app (i goto http://somesite.com in a browser to test). Can someone suggest a way to debug a setup like this (in visual studio) that does not include using http://localhost?
I understand that this can most likely be done using remote debugger, if that is the best way can someone explain how thats setup (or a link to a good article).

Set up a virtual machine, and run the web app in the VM. If you have two network adapters in the machine, you can even set things up so the network traffic goes out one, to a switch, and back in the other to the VM (I've done this sometimes so I could capture the traffic with WireShark).

Related

Unable to connect to localhost when working in the domain

Working in the local environment I'm quite often getting errors on communication between the visual studio, IIS, IIS-Express and the browser (any combination). Everything is working on closing down the computer and doesn't any more when the computer restarts. Problems have started when the computer joined the domain.
I've spend hours searching for a solution to the problem. It looks as Widows Defender is to blame which is triggering different rules after I've joining the domain. It is enough to switch off the firewall, start any web application and enable the firewall. Simple (yet annoying) but working (what is most important).

Remote debug a Windows service using VS2012

I've tried to find an answer to this before posting this question. I've got a windows service running on another machine. I've written the service in C# and the directory from which the service executable runs holds both executable and debug files (.pdb). I'm attempting to remote debug the service for the first time using VS 2012 Remote debugging. I'm able to attach to the service process successfully. However, as this is my first time I'm not sure what I can do next. I've clicked the pause button and that pauses the service on the line ServiceBase.Run(ServicesToRun) which isnt much use to me. The service has a timer which sets off every 30 seconds and will run the code in the timer event.
My question is ... is there a way of stepping through the code using the debugger in such a scenario.
Do I need to have some debug specific code already in my codebase so that when a debugger attaches it will take me to a place in the code from where i can step through the code?
Thanks,
Andrew.
There are several ways to debug your developed remote application or windows service. If you were in your machine(local) that would be simple to debug.
System.Diagnostics.Debugger.Launch();
But as you are in different machine it depends how your both Machines are connected. Which means you have some limitations on debugging remote application/services.
A Quick search gave me the following result that seemed helpful to me for you,
You can use Remote Debugging Monitor that visual studio use for connecting to remote device and debugging. You can have a clear instruction here on How to: Run the Remote Debugging Monitor.
There's another tool which lets you debug remote application's after a proper setup. But it has some limitations or conditions that you must abide by.
Here is the tool named Remote Tool, you can find a detailed setup process from MSDN here on How to: Set Up Remote Debugging.
It has been clearly quoted there about the prerequisites for using this tool. But still I'm rephrasing those again for quick reviewers.
Prerequisites to use Remote Tool for Visual Studio
To debug on a remote device:
The remote device and the Visual Studio computer must be connected over a network or connected directly through an Ethernet cable. Debugging over the internet is not supported.
The remote device must be running the Remote Tools for Visual Studio 2012.
You must be an administrator to install the remote tools on the remote device. To communicate with the remote tools, you must have user access to the remote device.
Feel free to share if you get to a better and working solution.
Thanks for your response. It reminded me to post my solution here for others like me.
The solution is simple (It always is once you know it).
Ensure that you are running the same code on the target machine as you have open in Visual Studio. It has to be the same assembly and version else the debugger will not hit your breakpoints. Ensure you have your breakpoints setup where you want the debugger to break execution. Then attach to the target machine process and wait for the timer to kick in and run the process where you breakpoint is set.
Hope this helps.
Andrew.

Getting Visual Studio debugging to work when running in Parallels

I've got a Windows 7 machine set up on Paralells.
Everything is working fine. Can access internet from IE or other browsers on my Parallels.
However, when trying to debug a web application in Visual Studio 2010 (by pressing F5 for example) then my default browser in OSX launches, which is great, with localhost:4243 (or whatever port Cassini has allocated on my vm)
Naturally, this doesn't find anything...
What do I need to do to either my parallels vm, or the settings on OSX to get debugging working? ie- my mac talking to the vm?
Make sure you are on the same network.
Use IIS.
Like so:
Your Win-machine has a name, let's say it's called "myWin7machine". Change "localhost:4243" to "myWin7machine:4243" in the browser.
If this doesn't work (well... it shouldn't) you might have the firewall on or the network not bridged. Let's start with the bridging.
Time to check some basics - be on the same network
Check your IP address. It's "ipconfig" on the Win machine and "ifconfig" on the mac; both run from the command prompt. The IP address should be something like 10.4.... or 192.168... on both. The important thing is that only the last number is different. (this is technically not correct but works for 99% of the cases) If they are equal (except the last) you are bridged - which means both machines are on the same network. If they differ too much you had running the Win machine's network "inside" the Mac's. Go to the settings for Parallels (in windows: move your mouse to the top to show Parallel's menu and go to Devices->Network and something "(bridged)". Wait until the balloons disappear and check ipconfig again.
Check that you can ping the Win machine from the Mac. Ping functionality might be turned off in the Win machine but probably isn't.
Now we know we are on the same network.
Still doesn't work
Can you do http://myWin7machine:4243 from the mac? Well.. you shouldn't be able to.
Can you do it from the Win machine? You should.
IIRC Cassini doesn't talk to strangers. I.e. it doesn't talk to anything but localhost.
If I am wrong - just open port 4243 in the firewall on the win machine and you should be good to go.
But otherwise...
Time to change web server.
Install IIS on the win machine.
In the Mac: surf to http://myWin7machine and see the IIS7 logo show.
If you don't you have a firewall issue. Open port 80. Try again.
If you have come this far then you can surf from the Mac to the IIS on the Win machine.
Time to set up your VS solution
Open the IIS admin GUI. Create a new Site. Let's say you call it MyTestSite. (you can always rename it later) Point it to your VS solution's web. Typically the same folder as web.config resides in. On the win machine: try surfing to "http://localhost/MyTestSite". Your site should show up. You might get an Apppool error.
Now try http://myWin7machine/MyTestSite on the Mac. It should work.
ROCK!
Time to set up debugging in VS
For debugging in IIS you have to connect to the process. In Win7 it requires elevated privileges so either you restart VS as admin or you try to connect and VS will do it for you.
The menu in VS is Debug->Attach to process and you choose w3wp.exe.
This is how you debug faster anyway - by connecting. Restarting your web for every debugging session is a waste of time.
To make connecting faster - use ctrl-alt-p and the continue with using the keyboard.
To make connecting even faster use a macro.
There is more info in these 4 articles: http://www.selfelected.com/tag/iis/
Set a breakpoint. Refresh your browser and the breakpoint should be hit.
Time to hack some code
Good luck!
I'm using Windows 10, VS 2015, Parallels 11 on iMac with OS X El Capitan (10.11.5). The following are the steps that worked for me:
On Windows side:
Get the IP (run ipconfig command in command window)
Get the host name (run hostname command in command window)
In control panel look for Windows Firewall -> Advanced Settings and add a new inbound rule and a new outbound rule. For both make sure you select Port, Allow Connection, TCP and specific IPs. I added a range of IPs 45000 - 45999 but you can select the range you like.
In Visual Studio:
Look for project properties and under web section change Server settings to look something like this.
Instead of "winmac" you will use the host name found in "Windows Side - Step 2". The port can be any number inside the range you setup for your firewall rules.
On Mac OS side:
Update /etc/hosts file. At the end of the file add the IP and host name that we found on steps 1 and 2 of the "Windows side" section. When you finish this step the file should like something similar to this.
Ready to debug:
Now you can start debugging in your Mac from Visual Studio. Make sure that before start the debugging process you select "Open In Mac" option (instead of Chrome or IE in your debugging options in visual studio).

Is it possible to easily compile and run code in another machine in Visual Studio/Eclipse?

Let's say I am developing a program that needs a bit more power than a netbook can provide and I have a good computer at home connected to the internet.
Is there any easy way to code in the netbook while I'm not at home and then when building, making it go and run on the computer at home?
I know running programs on other computers isn't a problem, but I'd like to know if it is possible to have an easy experience (it's still possible to debug, etc).
Thanks
It is definitely possible for Java code and Eclipse. But there are issues as well.
It helps a great deal if you have a fixed IP.
You need to open up ports on your firewall to be able to
copy your code into your PC
remote debug and upload your application
The last step will create issues with security that you need to address. I use ssh and public/private key to secure my connections.
In general, what you are asking is not much different to releasing a code to a server and debugging it. And normally servers sit somewhere on the internet or cloud.

IIS and VS, How do they work together?

I'm a bit confused.
When I type in my browser a "local" address (of a web site I'm editing on VS), IIS can handle it. How is that so? How can IIS know what's my latest web site version? What's the difference between typing the address in the browser and compiling the web site, and what does localhost has to do with all of that? And last one - is the IIS on my machine accessible to other computers on the net?
Edited the last one..
Thanks a lot.
localhost is an alias for the loopback address 127.0.0.1. It's not actually hard-coded; you can find it in C:\WINDOWS\system32\drivers\etc\hosts.
Pointing your browser to http://localhost/... will open port 80 on your local machine, which is the port IIS listens on by default. IIS doesn't actually know your website's latest version. It will simply find whatever assemblies and other files it has been directed to use, in whatever state they are in. Compiling will generate new assemblies to match your latest code, and IIS will pick those new assemblies up on the next request that hits the site.
The localhost address isn't accessible from other machines. They will almost certainly have the same alias, pointing to their loopback interface.

Resources